changing the ode inside ode45

1 次查看(过去 30 天)
Haya M
Haya M 2020-11-16
Hi everyone, I'm trying to solve an ode using ode45 which comes basically from matrix second order ode.
My idea is to solve first for dudx(2)=(sin(x)-z)*u(1) then solve for dudx(2)=(cos(x)-z)*u(1) as well as
adding the new solution to the first one to build a matrix of these two solutions.
I've tried this but because I have a function with a variable x so it doesnt work as a parameter
inside the function hundle.
Any idea would be appreciated and here is my code:
clear all
z=-1;
N=10;
xspan = [0 2*pi];
u01 = [1 0];
u02 = [0 1];
opts = odeset('RelTol',1e-9,'AbsTol',1e-9);
[u1] = ode45(@(x,u) ode(x,u,z),xspan,u01,opts);
[u2] = ode45(@(x,u) ode(x,u,z),xspan,u02,opts);
x1 = linspace(0,2*pi,N);
y1 = deval(u1,x1);
y2 = deval(u2,x1);
y1 = y1(:,end);
y2 = y2(:,end);
Phi = [y1 , y2];
function dudx = ode(x,u,z)
dudx = zeros(2,1);
dudx(1) = u(2);
dudx(2) = (sin(x)-z)*u(1);
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by