how can i get the values of y1, y2? i am only getting the graph.
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Saswati
el 2 de Abr. de 2025
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 comentarios
Respuesta aceptada
Stephen23
el 2 de Abr. de 2025
Editada: Stephen23
el 2 de Abr. de 2025
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 comentarios
Stephen23
el 2 de Abr. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!