I am not getting the graph of this code i have attached. Can someone help me?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Shrinking_bvp4c()
function Shrinking_bvp4c
clc
clear all
clear all
% defining parameters
k=0.5,K=0.8,M=0.3,S=2.0;
sol1 = bvpinit(linspace(0,20,25),[1 1 1 0]);
sol = bvp4c(@bvp2D,@bc2D,sol1);
x = sol.x;
y = sol.y;
%%% Plotting of the velocity
figure (1)
plot(x, y(2, :) ,'linewidth', 1)
hold on
xlabel('\eta', 'fontweight', 'bold', 'fontsize', 16)
ylabel('f^{\prime}(\eta)', 'fontweight', 'bold', 'fontsize', 16)
%% Residual of the boundary conditions
function residual = bc2D(y0, yinf)
residual=[y0(1)-S; y0(2) - 1; yinf(2)];
end
%% System of First Order ODEs
function yvector = bvp2D(t,y)
yy1 = 1/y(1)*(y(2)*y(2)-y(1)*y(3)-y(4)+k*(2*y(2)*y(4)-y(3)*y(3))+M*y(2)+K*y(2));
yvector = [y(2);y(3);yy1];
end
end
2 Commenti
Torsten
il 15 Feb 2025
If you have 4 solution variables, you need 4 differential equations and 4 boundary conditions. You only define 3 equations and 3 boundary conditions.
Walter Roberson
il 15 Feb 2025
The fact that you access y(4) inside bvp2D shows that you really do need 4 states. You need to return the derivative for all 4 states.
Risposta accettata
Karan Singh
il 18 Feb 2025
As Torsten and Walter have correctly pointed out the same. There are a few things missing.
- There is a mismatch in system dimensions. You initialize the solution with a 4‑element guess ([1 1 1 0]), which implies your system should have 4 first‑order ODEs. However, your function "bvp2D" returns only 3 derivatives : "yvector = [y(2); y(3); yy1];" Yet, within the calculation of "yy1", you use "y(4)", which suggests that a fourth state variable is expected.
- There is a mismatch in boundary conditions. In your boundary condition function "bc2D", you provide only 3 conditions: "matlabCopyEditresidual = [y0(1)-S; y0(2)-1; yinf(2)];" For a system with 4 unknown functions, you need 4 boundary conditions.
If your system is meant to be 4‑dimensional then You need to complete your ODE system by defining an expression for the derivative of the fourth state variable. Also, add an appropriate boundary condition for y(4) in "bc2D".
If your system is meant to be 3‑dimensional then Remove the extra state from your initial guess (change [1 1 1 0] to a 3‑element vector, for example [S, 1, ?] with an appropriate guess for the third component) and adjust the boundary conditions accordingly.
Karan
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!