4th order ODE, 4 boundary conditions
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
Torsten
il 11 Lug 2022
Modificato: Torsten
il 11 Lug 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 Commenti
MOSLI KARIM
il 16 Feb 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 Commenti
Vedere anche
Categorie
Scopri di più su Numerical Integration and Differential Equations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!