From: Stephen on 14 Apr 2010 03:32 I am trying to solve a system of 6 ODE's where on the 2nd ODE has a desired final value; however, it is not a BVP. I am trying to include a while loop to adjust the initial value for this equation until the desired tolerance for the final value, eq2(end), is reached. The error I am getting is: 'Index exceeds matrix dimensions. Error in ==> mars_ascent_vehicle_optimization at 46 while abs(gamma_2{J}(K))>0.01' Here is my code. The while loop is located below the break. clear clc format short g Vo=0.001; Go=90; Ao=0; lat=0; long=0; head=90; head=90-head; p1=0; p2=2.269; p3=1.4; p4=0; thrust_data MAX=max(tt); incr=max(tt)/(length(tt)-1); K=(((MAX)/incr)+1); x0=[Vo Go*(pi()/180) Ao lat*(pi()/180) long*(pi()/180) head*(pi()/180)]; p=[p1*pi()/180 p2 p3 p4]; for N=2:K-1 tspan{N}=0:incr:N*incr; [t{N},x{N}]=ode45(@mars_ascent_trajectory_burn,tspan{N},x0,[],p); V{N}=x{N}(1:end,1); gamma{N}=(180/pi()).*x{N}(1:end,2); A{N}=x{N}(1:end,3); LA{N}=(180/pi()).*x{N}(1:end,4); LO{N}=(180/pi()).*x{N}(1:end,5); H{N}=-((180/pi()).*x{N}(1:end,6))+90; for J=N:K gamma_2{J}={}; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% while abs(gamma_2{J}(K))>0.01 tspan_2{N}=tspan{N}(end):incr:MAX; Go_2(J)=gamma{N}(end)-0.001*(sind(gamma_2{J}(end))/(abs(sind (gamma_2{J}(end))))); x0_2{J}=[V{N}(end) Go_2(J) A{N}(end) LA{N}(end)*(pi()/180) LO{N} (end)*(pi()/180) (pi()/2)-H{N}(end)*(pi()/180)]; [t_2{J},x_2{J}]=ode45(@mars_rocket_trajectory_burn_2,tspan_2 {J},x0_2{J},[],p); V_2{J}=x_2{J}(1:end,1); gamma_2{J}=(180/pi()).*x_2{J}(1:end,2); A_2{J}=x_2{J}(1:end,3); LA_2{J}=(180/pi()).*x_2{J}(1:end,4); LO_2{J}=(180/pi()).*x_2{J}(1:end,5); H_2{J}=-((180/pi()).*x_2{J}(1:end,6))+90; end end end I think it has something to do with the fact that I am asking the while loop to test the last value in the gamma_2 entry for K minus one different gamma_2 vectors. Thanks in advance for any help offered.
|
Pages: 1 Prev: Avoid local stack variables with 2007b Next: setting background of edit text to 'transparent' |