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));
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.