4th order ODE, 4 boundary conditions
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Torsten
el 11 de Jul. de 2022
Editada: Torsten
el 11 de Jul. de 2022
%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 comentarios
MOSLI KARIM
el 16 de Feb. de 2023
%%
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 comentarios
Ver también
Categorías
Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!