Using ODE45 for first order diff equation with three different variables

34 vues (au cours des 30 derniers jours)
PetronasAMG
PetronasAMG le 13 Sep 2021
Modifié(e) : darova le 14 Sep 2021
So, I am trying to use ODE45,
say dx/dt = (0.1*x)+(0.25*y)-(9.8*z)
I am trying to graph the behavior of x,y and z from time (0 to 100). What should i do to set up as in funciton file?
i tried
function dxdt = func(t,x,y,z)
dxdt = (0.1*x)+(0.25*y)-(g*z);
end
%main script
tspan = [0 100];
xint = 0;
yint = 0;
zint = 0;
[t,x,y,z] = ode45(func,tspan,xint,yint,zint);
But after i run this code i am getting an error says not enough input arguments.I am still adpoting the concept of using ode function but Please help!
I need to plot x,y,z from 0 to 100
  1 commentaire
Wan Ji
Wan Ji le 14 Sep 2021
Hi, you should have three equations for solving ode of x,y,z with respect to t. But you only provided one

Connectez-vous pour commenter.

Réponse acceptée

Wan Ji
Wan Ji le 14 Sep 2021
For example
function dxdt = func(t,x,g)
dxdt = zeros(3,1);
dxdt(1) = (0.1*x(1))+(0.25*x(2))-(g*x(3));
dxdt(2) = (0.1*x(1))+(0.25*x(2))-(g*x(3));
dxdt(3) = (0.1*x(1))+(0.25*x(2))-(g*x(3));
end
The main function
tspan = [0 100];
g = 10;
[t,x] = ode45(@(t,x)func(t,x,g),[0,100],[0;0;0]);
xsol = x(:,1);
ysol = x(:,2);
zsol = z(:,3);

Plus de réponses (0)

Tags

Produits


Version

R2015b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by