4th order ODE, 4 boundary conditions

조회 수: 5 (최근 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 CenterFile Exchange에서 Numerical 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