To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016
Basically as the title mentions, I am having a problem that an equation I'm using becomes a 1x2 double matrix, with a second member inside being NaN. Whilst debugging I checked the members within the equation, all of them seem to be 1x1, hence I am wondering what could be the reason for this, as at the moment I can't use the member found from the calculations as it causes further errors because it's a larger matrix than it should be.
Here is the code in which the equation goes wrong (the equation itself is x(k-1)=(sqrt(l3^2-d(k-1).^2)) ):
function [t, z] = Angle(tInc) % Set init;ial conditions global x; t(1)=0; z(1,1)=0; %1.3814; angle in radians z(2,1) = 0; %angular velocity mast=6; l=1.15; %half the widht of the catamaran l3=sqrt(mast^2+l^2); %resultant of half the width and mast k=1;
while z(1,k)<=1.381426277 %0.18937005; %d=-mast-r:0; k=k+1; d=-mast*cos(z(1,k-1))+l*sin(z(1,k-1)); x(k-1)=(sqrt(l3^2-d(k-1).^2)); %shortest distance between the force of the air bag and hull t(k)=t(k-1)+tInc; [z(:,k)] = RKF(t(k-1), z(:,k-1), tInc); end end
This function also uses two more functions, I am unsure whether those are necessary, as the NaN occurs before calling the functions out, but just in case here they are:
function [z] = RKF(t, z, tInc) global x; %tolh=0.000002; %chosen tolerance for time increment. Used for RK5 %RK4 A=tInc*Dz(t,z); B=tInc*Dz(tInc/2+t,z+A/2); C=tInc*Dz(tInc/2+t,z+B/2); D=tInc*Dz(tInc+t,z+C); z=z + (A+2*B+2*C+D)/6; end
function [dz] = Dz(t, z)
g=9.81; %/sqrt((6400+z(2)/1000)/6400); m = 44.6; % Mass (kg) a=1030; %water density %a = (p*M)/(R*T); % Air density (kg/m^3) l=1.15; %half the width of main body of catamaran r=0.3; %diameter of missile (m) V=(4*pi*r^3)/3; %volume I=391.5; %moment of inertia for the catamaran mast=6; %length of mast
l3=sqrt(mast^2+l^2); %distance between air bag and hull Fb=a*g*V*x; %buoyancy force of the air bag Fg=m*g*2*l*cos(z(1));
%Transpose the dz vector dz=dz';
I hope someone may be able to help with this.
Thank you for your time.
At the command line do
>>dbstop if naninf
Then rerun your code. When it stops at the K>> prompt, show us the output of
Also paste the error messages for us.
and before that
with m, g, l, and z(1) all being scalars, so Fg is a scalar, so look at Fb
a, g are constants, V you can trace back to see must be a scalar. But x? According to whos, x is 1 x 2... which would make Fb 1x2, which would make (Fb-Fb)/I into 1x2, which is not going to fit into dz(2).
You do not have any assignments to x, so the reason it is 1x2 lies in whatever created it outside of this. You will probably find that x(2) is NaN that that that is why the second element of the expression becomes NaN.