solving the differential equation with ode 45 for different values of z
2 views (last 30 days)
Show older comments
SATYAJIT BHATTACHARJEE
on 28 Sep 2020
Commented: Ameer Hamza
on 28 Sep 2020
Hi all,
I have 4th order diff. eqn.(z is independent variable, x is dependent variable) which is to be solved using ode 45 for a range of values for z. THe code is atached but shows error.
syms x(z) T Y
dx=diff(x);% dx== (dx/dz)
d2x=diff(x,2);
d3x=diff(x,3);
d4x=diff(x,4);
k=1;
re=0;
g=1;
a=-1;
z=linspace(0,1,10)
eqn2=((-re/g)*(a+g*i*k*z)*(d2x - k^2*x)) + (d4x - 2*k^2*d2x + k^4*x)==0
[VF] = odeToVectorField(eqn2);
coupled2 = matlabFunction(VF, 'Vars',{T,Y});
output2=coupled2;
% array of initial values
x0=0;
dx0=0;
d2x0=1;
d3x0=0;
tspan1=linspace(1,0,10); % range of z
t10 = [x0,dx0,d2x0,d3x0]; % array of initial values
[R1,V1] = ode45(@(T,Y)coupled2(T,Y),tspan1,t10)
2 Comments
Accepted Answer
Ameer Hamza
on 28 Sep 2020
z is independent variable, so you don't need to put this line in your code
z=linspace(0,1,10)
it messes things up later. Also, T is not used anywhere in equations, but you have used it in odeToVectorField(). Try the following code
syms x(z) Y
dx=diff(x);% dx== (dx/dz)
d2x=diff(x,2);
d3x=diff(x,3);
d4x=diff(x,4);
k=1;
re=10;
g=1;
a=-1;
eqn2 = ((-re/g)*(a+g*i*k*z)*(d2x - k^2*x)) + (d4x - 2*k^2*d2x + k^4*x)==0
[VF] = odeToVectorField(eqn2);
coupled2 = matlabFunction(VF, 'Vars',{z, Y});
output2=coupled2;
% array of initial values
x0=0;
dx0=0;
d2x0=1;
d3x0=0;
tspan1=linspace(1,0,10); % range of z
t10 = [x0,dx0,d2x0,d3x0]; % array of initial values
[R1,V1] = ode45(@(T,Y)coupled2(T,Y),tspan1,t10)
2 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!