I am not getting the graph of this code i have attached. Can someone help me?

조회 수: 3 (최근 30일)
Shrinking_bvp4c()
k = 0.5000
K = 0.8000
M = 0.3000
Error using bvparguments (line 99)
Error in calling BVP4C(ODEFUN,BCFUN,SOLINIT):
The derivative function ODEFUN should return a column vector of length 4.

Error in bvp4c (line 119)
bvparguments(solver_name,ode,bc,solinit,options,varargin);

Error in solution>Shrinking_bvp4c (line 9)
sol = bvp4c(@bvp2D,@bc2D,sol1);
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
Torsten
Torsten 2025년 2월 15일
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
Walter Roberson 2025년 2월 15일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Karan Singh
Karan Singh 2025년 2월 18일
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

추가 답변 (0개)

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by