how can i get the values of y1, y2? i am only getting the graph.
8 次查看(过去 30 天)
显示 更早的评论
function Shrinking_bvp4c
clc
clear all
clear all
% defining parameters
k=0.2,K=0.2,M=0.2,S=2;
sol1 = bvpinit(linspace(0,3,30),[1 0 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^/(\eta)', 'fontweight', 'bold', 'fontsize', 16)
%% Residual of the boundary conditions
function residual = bc2D(y0, yinf)
residual=[y0(1)-S; y0(2)+1; yinf(2); yinf(3)];
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);y(4);yy1];
end
end
0 个评论
采纳的回答
Stephen23
2025-4-2
编辑:Stephen23
2025-4-2
Return them as function outputs:
[x,y] = Shrinking_bvp4c % here are the values
plot(x, y(2, :) ,'linewidth', 1)
hold on
xlabel('\eta', 'fontweight', 'bold', 'fontsize', 16)
ylabel('f^/(\eta)', 'fontweight', 'bold', 'fontsize', 16)
function [x,y] = Shrinking_bvp4c % <- define the output arguments here.
%!!!!!!!!!!! Do NOT put anti-pattern CLEAR at the top of a function !!!!!!!!!!
% defining parameters
k=0.2;
K=0.2;
M=0.2;
S=2;
sol1 = bvpinit(linspace(0,3,30),[1 0 1 0]);
sol = bvp4c(@bvp2D,@bc2D,sol1);
x = sol.x;
y = sol.y;
%% Residual of the boundary conditions
function residual = bc2D(y0, yinf)
residual=[y0(1)-S; y0(2)+1; yinf(2); yinf(3)];
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);y(4);yy1];
end
end
2 个评论
Stephen23
2025-4-2
"if I put the above line , I am only getting the values of x. how to get values of y?"
I already showed you that in my answer (and also linked to the documentation which explains how).
Here it is again, you have to call your function with TWO output arguments (not ONE like you are doing):
[x,y] = Shrinking_bvp4c
%^^^ !!!! you need TWO output arguments when you call the function !!!!
Lots of MATLAB functions have multiple outputs, this is a very important basic MATLAB syntax.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!