function Q2am0 = 120000;n = 15;mf = m0/n;Isp = 320;g = 9.81;T = 1.4*m0*g;me = T/(Isp*g);t0 = 0;tb = (m0 - mf)/me;tspan = [t0 tb];gamma0 = 1.568;m = [m0 mf];ht = 110;function dvdt = velocity(t,g,T,m,gamma0,ht,littlegam)while alt <= htdvdt = (T - m*g*sin(gamma0))/m ; endwhile alt > ht dvdt = (T - m*g*sin(littlegam))/m;endendfunction [t,v] = vel(tspan,g,T,m,gamma0,ht,littlegam,t)v0 = 0;[t,v] = ode45(@(t,m) velocity(t,g,T,m,gamma0,ht,littlegam) ,tspan , v0);output(t,v)endfunction dhdt = altitude(t,vel,littlegam,ht,gamma0)v = vel;while ht >= alt dhdt=v.*sin(gamma0);endwhile alt > htdhdt = v.*sin(littlegam);endendfunction [t,h] = alt(tspan, vel, littlegam, ht, gamma0)h0 = 0;[t,h] = ode45(@(t,vel) altitude(t,vel,littlegam,ht,gamma0) , tspan, h0);endfunction dgammadt = pitch_angle(t,g0,littlegam,vel,Re,alt,gamma0,ht)h = alt;v = vel;while ht >= altdgammadt=(-(1./v)).*(g0-((v.^2)./(Re+h))).*(cos(gamma0));endwhile alt > htdgammadt=(-(1./v)).*(g0-((v.^2)./(Re+h))).*(cos(littlegam));endendfunction [t,gamma] = littlegam(g0,alt,Re,vel,gamma0,tspan,ht)[t,gamma] = ode45(@(t,vel) pitch_angle(t,g0,littlegam, vel, Re, alt, gamma0, ht) , tspan, gamma0);end function dxdt = downrange_dist(Re,alt,vel,littlegam,ht,gamma0,t)while ht >= altdxdt=(Re./(Re+ h)).*v.*cos(gamma0);endwhile alt > htdxdt=(Re./(Re+ alt)).*vel.*cos(littlegam);endendfunction [t,x] = dis(Re,alt,vel,littlegam,tspan,ht,gamma0)x0 = 0;[t,x] = ode45(@(t,alt) downrange_dist(Re,alt,vel,littlegam,ht,gamma0,t), tspan, x0);endplot(tspan,vel);plot(tspan,alt);plot(tspan,littlegam);plot(tspan,dis);end
MATLAB: Trying to solve 4 coupled differential equations using ode45 and keep getting the error not enough input arguments
coupled differential equationsode45
Best Answer