4th order ODE, 4 boundary conditions
11 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(2 个)
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
0 个评论
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Boundary Value Problems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!