solving differential equations with ode 45
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Guillaume Ryelandt
le 5 Avr 2020
Commenté : Ameer Hamza
le 5 Avr 2020
Hi everyone,
I have a little problem using ode45 to solve this equation
with initial conditions
. But every time i try to run my script, i get this message of error


Error in Ryelandt_288861_Assignment2>@(t,z)EX_3_ode(z,t,M(1),c,c3,J)
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 33)
[t_out1,Z_out1] = ode45( @(t,z) EX_3_ode(z,t,M(1),c,c3,J), xx, IC1, opts);
Could someone help me with this ?
%% Initiate the script
clc; clear; close all
xx = linspace(0,10,1e3).';
%% 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,20,25,55]; %[Nm]
%% Question 3
%initial conditions
IC1=[0; 0];
opts= odeset('RelTol',1e-8,'AbsTol',1e-10);
[t_out1,Z_out1] = ode45( @(t,z) EX_3_ode(z,t,M(1),c,c3,J), xx, IC1, opts);
%% Function definition
function dzdt1 = EX_3_ode(z,M,c,c3,J)
dzdt1(1,1) = z(2) ;
dzdt1(2,1) =(M-c.*z(2)-c3.*z(2)^3)./J ;
end
0 commentaires
Réponse acceptée
Ameer Hamza
le 5 Avr 2020
You need to change it like this
[t_out1,Z_out1] = ode45( @(t,z) EX_3_ode(t,z,M(1),c,c3,J), xx, IC1, opts); % first input of EX_3_ode is t
%% Function definition
function dzdt1 = EX_3_ode(t,z,M,c,c3,J) % first input should be t, if it is not used, replace it with ~
dzdt1(1,1) = z(2) ;
dzdt1(2,1) =(M-c.*z(2)-c3.*z(2)^3)./J ;
end
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!