solving a set of differential equations with ode45
1 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I am trying to solve the set differential equations (see in code) with ode 45 but I suppose that i haven't declared my function properly. Does anyone have an idea on the way to fix this problem... I get this message of error...
%% Initiate the script
clc; clear; close all
% yy = 1-2*xx+3*xx.^2;
% %% Check the stored value of the selected point
% [x1 y1]
%% Question 3
%initial conditions
xx = linspace(0,10,1e3).';
IC1=[0; 0; 298; 298];
opts= odeset('RelTol',1e-8,'AbsTol',1e-10);
[tout,Xout] = ode45(@(t,x)mydyn(t,x),xx,IC1,opts);
%% Function definition
function dx = mydyn(t,x)
% Define the parameters
Ct= 200; %[J/K]
ht=140; %[W/m^2K]
At=0.02; %[m^2]
he=200; %[W/m^2K]
Ae=pi; %[m^2]
Te= 298; %[K]
V=6*pi; %[m^3]
rho=1; %[kg/m^3]
cp=4200; %[J/kgK]
J=300; %[kgm^2]
c=2; %[Nms]
c3=0.1; %[Nms^3]
cq=0.09; %[Ws^4]
M=[5,15,25,55];
T=x(1);
Tt=x(2);
theta=x(3);
thetadot=x(4);
%state model
dT=(V*rho*cp)^-1*(he*Ae(Te-T)+ht*At*(Tt-T)+cq*thetadot^4);
dTt=(ht*At)*(Ct)^-1.*(T-Tt);
dtheta=thetadot;
dthetadot=(M-c*thetadot-c3*thetadot^3)./J;
dx=[dT,dTt,dtheta,dthetadot]';
end
Error in Ryelandt_288861_Assignment2>@(t,x)mydyn(t,x)
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in Ryelandt_288861_Assignment2 (line 32)
[tout,Xout] = ode45(@(t,x)mydyn(t,x),xx,IC1,opts);
0 个评论
采纳的回答
James Tursa
2020-4-5
Initial conditions is a 4-element vector:
IC1=[0; 0; 298; 298];
But in your derivative function you have this:
M=[5,15,25,55]; % 4-element vector
:
dthetadot=(M-c*thetadot-c3*thetadot^3)./J; % 4-element vector
dx=[dT,dTt,dtheta,dthetadot]'; % 4-element vector in that last spot
So dx ends up being 7 elements instead of 4, hence the mismatch error.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!