
Couple ODE System not enough Input arguments, Why?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hey all,
I have a coupled system of ODE's that I want to solve and followed the instructions. However, there seems to be an error with the input arguments. Could somebody help?
Best
% Define the boundary value problem
solinit = bvpinit(linspace(0,1,10), @guess);
% Solve the boundary value problem
sol = bvp4c(bvpfun, bcfun, solinit);
% Plot the solution
x = linspace(0,1,100);
y = deval(sol, x);
plot(x, y(1,:), 'b-', 'LineWidth', 2);
hold on
plot(x, y(2,:))
xlabel('x');
ylabel('y');
title('Solution of Second Order ODE with BVP');
grid on;
function dydx = bvpfun(x, y)
dydx = zeros(3, 1); % Initialize dydx as a column vector
dydx(1) = y(3) + y(1);
dydx(2) = y(1) - 2/y(3);
dydx(3) = y(1) - 1;
dydx = [dydx(1); dydx(2); dydx(3)];
end
function res = bcfun(ya,yb)
res(1) = ya(1);
res(2) = ya(2);
res(3) = ya(3);
end
function y = guess(x)
y = [0; 0; 0];
end
2 commentaires
Sam Chak
le 3 Avr 2024
From the dynamics

the condition given at the boundary
,
,
causes the singularity
.
Réponses (3)
Aquatris
le 3 Avr 2024
Modifié(e) : Aquatris
le 3 Avr 2024
You should use @ symbol before the functions in your bvp4c call. Now you have another error, good luck solving it :D hint: what happens when y(3) = 0.
% Define the boundary value problem
solinit = bvpinit(linspace(0,1,10), @guess);
% Solve the boundary value problem
sol = bvp4c(@bvpfun, @bcfun, solinit);
% Plot the solution
x = linspace(0,1,100);
y = deval(sol, x);
plot(x, y(1,:), 'b-', 'LineWidth', 2);
hold on
plot(x, y(2,:))
xlabel('x');
ylabel('y');
title('Solution of Second Order ODE with BVP');
grid on;
function dydx = bvpfun(x, y)
dydx = zeros(3, 1); % Initialize dydx as a column vector
dydx(1) = y(3) + y(1);
dydx(2) = y(1) - 2/y(3);
dydx(3) = y(1) - 1;
dydx = [dydx(1); dydx(2); dydx(3)];
end
function res = bcfun(ya,yb)
res(1) = ya(1);
res(2) = ya(2);
res(3) = ya(3);
end
function y = guess(x)
y = [0; 0; 0];
end
0 commentaires
Sam Chak
le 3 Avr 2024
Hi @Thanh Hoang
I have added these four lines to your original code. The modifications made are minimal.
%% ----- added these 4 lines -----
ivpfun = @bvpfun;
xspan = [0, 1];
yinit = [0; 0; 0];
sol = ode45(ivpfun, xspan, yinit);
%% ----- added these 4 lines -----
% sol = bvp4c(@bvpfun, @bcfun, solinit);
% Plot the solution
x = linspace(0,1,100);
y = deval(sol, x);
plot(x, y(1,:), 'b-', 'LineWidth', 2);
hold on
plot(x, y(2,:))
xlabel('x');
ylabel('y');
title('Solution of Second Order ODE with BVP');
grid on;
function dydx = bvpfun(x, y)
dydx = zeros(3, 1); % Initialize dydx as a column vector
dydx(1) = y(3) + y(1);
dydx(2) = y(1) - y(3)/2;
dydx(3) = y(1) - 1;
dydx = [dydx(1);
dydx(2);
dydx(3)];
end
0 commentaires
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
