changing the ode inside ode45
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!