Solving differential equation using ode45 with three variables
Ältere Kommentare anzeigen
Hi I'm trying to solve a simple second-order differential equation y''-2y'+y=0, with initial conditions where y'=0 and y=0.
I have successfully made a function of
function dydt=ode5( t, y)
dydt=zeros(2,1);
dydt(1)=y(2);
dydt(2)=2*y(2)-y(1);
end
but I want to make a function that can substitute dydt=p or some other symbol to simply put it as
function dydx=ode9(x,p,y)
p=zeros(2,1);
dydx=p;
dpdx=-p+2*y;
end
but I keep getting errors. Help!
7 Kommentare
Torsten
am 21 Aug. 2018
It's not possible to set a boundary condition for the second derivative for a differential equation of order 2. Only boundary conditions for the function itself and its first derivazive are allowed.
Jay Kim
am 21 Aug. 2018
I don't understand the sense of your code.
1. p is an input parameter, but you reset it to null with p = zeros(2,1).
2. You define dpdx, but the return variable of ode9 is dydx. So dpdx is not used.
Which differential equation do you intend to define in ode9 ?
Jay Kim
am 21 Aug. 2018
Jan
am 21 Aug. 2018
@Jay Kim: It is not clear to me, what you are asking for.
Torsten
am 21 Aug. 2018
The only meaningful I can think of is
[X,Y]=ode45(@(x,y)ode9(x,y(1),y(2)),tspan,y0)
function derivatives = ode9(x,y,yp)
derivatives = zeros(2,1)
dydx = yp;
dypdx = 2*yp-y;
derivatives = [dydx;dypdx]
end
Walter Roberson
am 21 Aug. 2018
Do I understand correctly that you would like to pass in as p some indication of which y entry to use?
Would the code always be as simple as dydx being assigned y indexed at some fixed value?
Akzeptierte Antwort
Weitere Antworten (1)
goutham baburaj
am 9 Jul. 2019
0 Stimmen
thanks
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!