Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Return of a complex answer.
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I'm trying to model an oscillation of a floating object but I'm having some trouble. When running the script there is an error referring to trying to calculate something with two different kind of numbers. The problem was isolated to some equations calculating things like the submerged volume of a cylinder and the projected area of a cylinder inside a while loop. These equations contain sine cosine and arcsin which return a real value for a specific input range. This is taken care of by if statements, so the equation isn't used when input values exceed the range. When running the script the output values, however, are complex and an error appears: In an assignment A(:) = B, the number of elements in A and B must be the same. Error in Floatingoscill (line 44) y(k+1)=y(k)+v*dt+0.5*a*dt^2; %Vertical Distance
With my limited matlab skills I tried to change number type by using abs() but to no avail. I wonder if it is possible to fix this problem at all.
Relevant code is shown below:
if y(k)<0
if y(k)>-rad
A=length*2*rad*cos(asin((rad+y)/rad)); %projected floater area
else
A=diam*length;
end
end
if y(k)<0
if y(k)>-diam
Fb=rho*g*length*2*rad^2*(asin(((-y)/rad)-1)+0.5*sin(2*asin(((-y)/rad)-1)))+rho*g*length*pi*rad^2;
else
Fb=2*rho*g*length*pi*rad^2;
end
else
Fb=0;
end
I hope somebody has some experience with this kind of problem and has a solution.
1 comentario
dpb
el 30 de Sept. de 2018
Editada: dpb
el 30 de Sept. de 2018
I suggest using the debugger and set a breakpoint to follow your logic and see where your algebra breaks down...
BTW, length is a builtin Matlab function
>> which length
built-in (C:\...\toolbox\matlab\elmat\length)
>>
I strongly suggest to not overload it but use some other variable name instead.
Also, remember that arguments for the base trig functions in Matlab are in radians, not degrees so ensure your input units are consistent with that. There are alternate routines with 'd' suffix for input in degrees...
Respuestas (0)
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!