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!