Set answers of first BVP as new boundary condition for second BVP
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello all,
I want to set the answer of one BVP as a boundary condition for a second equation. However, there seems to be an issue with evaluating the solution of the first BVP. Do you have suggestings how to solve this?
Best,
Thanh
% Solve the first BVP
solinit1 = bvpinit(linspace(0, 1, 10), [0 0]);
sol1 = bvp4c(@myFirstODEFun, @myFirstBCFun, solinit1);
% Evaluate the solution of the first BVP at x = 1
value_at_1 = deval(sol1, 1);
% Solve the second BVP
solinit2 = bvpinit(linspace(0, 1, 10), [0 0]);
sol2 = bvp4c(@mySecondODEFun, @mySecondBCFun, solinit2);
% Define the first ODE and its boundary conditions
function dydx = myFirstODEFun(x, y)
dydx = [y(2); -y(1)]; % Your first ODE here
end
function res = myFirstBCFun(ya, yb)
res = [ya(1); yb(2) - 1]; % Boundary conditions for the first ODE
end
% Define the second ODE and its boundary conditions, incorporating value_at_1
function dydx = mySecondODEFun(x, y)
dydx = [y(2); -2*y(1)]; % Your second ODE here
end
function res = mySecondBCFun(ya, yb)
res = [ya(1) - value_at_1(1); yb(1) - 2]; % Use value_at_1 in the boundary conditions
end
% Plot or analyze sol2 as needed
0 comentarios
Respuestas (1)
Torsten
el 8 de Abr. de 2024
Editada: Torsten
el 8 de Abr. de 2024
"value_at_1" is defined in the script part of your code, but it's not automatically visible in the functions you define. Either pass "value_at_1" to "mySecondBCFun" as additional input or use nested functions as done below.
main()
function main()
% Solve the first BVP
solinit1 = bvpinit(linspace(0, 1, 10), [0 0]);
sol1 = bvp4c(@myFirstODEFun, @myFirstBCFun, solinit1);
% Evaluate the solution of the first BVP at x = 1
value_at_1 = deval(sol1, 1);
% Solve the second BVP
solinit2 = bvpinit(linspace(0, 1, 10), [0 0]);
sol2 = bvp4c(@mySecondODEFun, @mySecondBCFun, solinit2);
hold on
plot(sol1.x,sol1.y(1,:))
plot(sol2.x,sol2.y(1,:))
hold off
grid on
% Define the first ODE and its boundary conditions
function dydx = myFirstODEFun(x, y)
dydx = [y(2); -y(1)]; % Your first ODE here
end
function res = myFirstBCFun(ya, yb)
res = [ya(1); yb(2) - 1]; % Boundary conditions for the first ODE
end
% Define the second ODE and its boundary conditions, incorporating value_at_1
function dydx = mySecondODEFun(x, y)
dydx = [y(2); -2*y(1)]; % Your second ODE here
end
function res = mySecondBCFun(ya, yb)
res = [ya(1) - value_at_1(1); yb(1) - 2]; % Use value_at_1 in the boundary conditions
end
% Plot or analyze sol2 as needed
end
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!