how can i get the values of y1, y2? i am only getting the graph.

6 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Stephen23
Stephen23 am 2 Apr. 2025
Bearbeitet: Stephen23 am 2 Apr. 2025
Return them as function outputs:
[x,y] = Shrinking_bvp4c % here are the values
x = 1×33
0 0.1034 0.2586 0.4138 0.5690 0.7241 0.8793 1.0345 1.1897 1.3448 1.4483 1.5517 1.6552 1.7586 1.8103 1.8621 1.9138 1.9655 2.0172 2.0690 2.1207 2.1724 2.2241 2.2759 2.3276 2.3793 2.4310 2.4828 2.5862 2.6897
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
y = 4×33
2.0000 1.8989 1.7565 1.6258 1.5074 1.4016 1.3084 1.2276 1.1587 1.1012 1.0687 1.0406 1.0165 0.9963 0.9874 0.9794 0.9721 0.9656 0.9598 0.9546 0.9500 0.9459 0.9424 0.9394 0.9368 0.9346 0.9328 0.9313 0.9291 0.9278 -1.0000 -0.9542 -0.8807 -0.8030 -0.7226 -0.6412 -0.5603 -0.4816 -0.4065 -0.3361 -0.2924 -0.2516 -0.2137 -0.1790 -0.1629 -0.1476 -0.1331 -0.1194 -0.1066 -0.0945 -0.0833 -0.0728 -0.0632 -0.0543 -0.0462 -0.0388 -0.0321 -0.0261 -0.0162 -0.0088 0.4296 0.4562 0.4886 0.5112 0.5232 0.5247 0.5158 0.4972 0.4700 0.4354 0.4091 0.3807 0.3507 0.3197 0.3040 0.2881 0.2723 0.2564 0.2407 0.2250 0.2095 0.1942 0.1792 0.1644 0.1500 0.1359 0.1222 0.1088 0.0834 0.0597 0.2759 0.2389 0.1778 0.1119 0.0436 -0.0244 -0.0895 -0.1490 -0.2008 -0.2430 -0.2653 -0.2828 -0.2954 -0.3033 -0.3055 -0.3066 -0.3067 -0.3058 -0.3039 -0.3012 -0.2976 -0.2932 -0.2881 -0.2824 -0.2761 -0.2692 -0.2618 -0.2541 -0.2375 -0.2199
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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 Kommentare
Saswati
Saswati am 2 Apr. 2025
function [x,y]=Shrinking_bvp4c
if I put the above line , I am only getting the values of x. how to get values of y?
Stephen23
Stephen23 am 2 Apr. 2025
"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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by