4th order ODE, 4 boundary conditions

6 ビュー (過去 30 日間)
Connor Thompson
Connor Thompson 2022 年 7 月 11 日
回答済み: MOSLI KARIM 2023 年 2 月 16 日
I have a 4th order ODE, with 4 boundary conditions.
The ODE problem is
y''''(x) = y(x)*y'''(x) - y'(x)*y''(x)
With the 4 boundary conditions:
y(0) = 0.1, y(1) = 0, y'(0) = 0, y'(1) = 0.
I started off my code by writing the ODE as a system of first order ODE's,
function dydx = ab(x,y)
dydx = zeros(4,1);
dydx(1) = y(2);
dydx(2) = y(3);
dydx(3) = y(4);
dydx(4) = y(1)*y(4) - y(2)*y(3);
Then defining the 4 boundary conditions,
function res = bc4(ya,yb)
res = [ya(1)-0.1; yb(1); ya(2); yb(2)];
Followed by:
solinit = bvpinit(linspace(0,0.05,1), [1, 0]);
sol = bvp4c(@ab, @bc4,solinit);
x = linspace(0,1);
y = deval(sol.x);
plot(x,y(1,:));
However, I already get an error on the second line,
"Not enough input arguements. Erron in __ (line 3)
dydx = y(2)"
Any ideas on what is going wrong?

回答 (2 件)

Torsten
Torsten 2022 年 7 月 11 日
編集済み: Torsten 2022 年 7 月 11 日
%solinit = bvpinit(linspace(0,0.05,1), [1, 0]);
solinit = bvpinit(0:0.05:1, [1, 0,0,0]);
sol = bvp4c(@ab, @bc4,solinit);
%x = linspace(0,1);
%y = deval(sol.x);
%plot(x,y(1,:));
plot(sol.x,[sol.y(1,:);sol.y(2,:)]);
function dydx = ab(x,y)
dydx = zeros(4,1);
dydx(1) = y(2);
dydx(2) = y(3);
dydx(3) = y(4);
dydx(4) = y(1)*y(4) - y(2)*y(3);
end
function res = bc4(ya,yb)
res = [ya(1)-0.1; yb(1); ya(2); yb(2)];
end

MOSLI KARIM
MOSLI KARIM 2023 年 2 月 16 日
%%
function answer_matlab
clc
clear all
close all
format long
mesh=20;
x=linspace(0,1,mesh)
solinit=bvpinit(linspace(0,1,10),[0.1 ;0 ;0; 0])
sol=bvp4c(@fct,@bc,solinit)
y=deval(sol,x)
figure(1)
hold on
plot(x,y(1,:))
function dxdy=fct(x,y)
dxdy=[y(2);y(3);y(4);y(1)*y(4)-y(2)*y(3) ];
end
function res=bc(ya,yb)
res=[ya(1)-0.1
yb(1)
ya(2)
yb(2)
];
end
end

カテゴリ

Help Center および File ExchangeNumerical Integration and Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by