我尝试将1x1 sym转换为浮动在下面的程序中,但它失败了。为什么?
罪魁祸首:
sol = ode45(M,[30 45],[double(H0) double(V0)]);
错误消息:
使用odearguments时出错(第111行)输入必须是浮点数,即 单身或双人。
ode45错误(第114行)[neq,tspan,ntspan,next,t0,tfinal,tdir, y0,f0,odeArgs,odeFcn,...
extra_credit_HW5_ME70(第60行)中的错误sol = ode45(M,[30 45],[subs(H0)subs(V0)]);
代码:
clc;
clear all;
close all;
%This program solves the rocket program by using a system of second order
%differential which I derived (see Homework 5)
%code explanation from http://www.mathworks.com/products/symbolic/code-examples.html? file=/products/demos/symbolictlbx/second_order_differential_equation/solve-a-second-order-differential-equation.html
Ve=3500;
Mo=400;
Me=5;
g=9.81;
Cd=.5;
Af=.2;
R=287
T=273.15;
Patm=101325;
syms y(t);
%Note: From the hw: "Take the density of air at sea level to be 1.21
%kg/m3." I decided to model the density with an exponential function p(h)=(Patm*exp(-g*y/(R*T))/(R*T))
V = odeToVectorField(diff(y, 2) == Ve*Me/(Mo-Me.*t)-g-.5*Cd* (Patm*exp(-g*y/(R*T))/(R*T)) *diff(y).^2*Af/(Mo-Me.*t));
M = matlabFunction(V,'vars', {'t','Y'});
sol = ode45(M,[0 30],[0 0]);
x = linspace(0,30,250);
y = deval(sol,x,1);
plot(x,y);
% legend('No air resistance, air resistance');
hold on;
Mo=350;
syms y(t);
%Initial conditions for case where mass is dumped.
H0=y(end);
V0=( (y(end)-y(end-1)) / (x(end)-x(end-1)) );
%Note: From the hw: "Take the density of air at sea level to be 1.21
%kg/m3." I decided to model the density with an exponential function p(h)=(Patm*exp(-g*y/(R*T))/(R*T))
V = odeToVectorField(diff(y, 2) == Ve*Me/(Mo-Me.*t)-g-.5*Cd* (Patm*exp(-g*y/(R*T))/(R*T)) *diff(y).^2*Af/(Mo-Me.*t));
M = matlabFunction(V,'vars', {'t','Y'});
sol = ode45(M,[30 45],[double(H0) double(V0)]);
x = linspace(30,45,500);
y = deval(sol,x,1);
plot(x,y,'cyan');
% legend('No air resistance, air resistance');
title('Rocket height versus time for stages launch')
xlabel('time (seconds)')
ylabel('height (meters)')