Borrar filtros
Borrar filtros

same value for first and second solution

3 visualizaciones (últimos 30 días)
Amir
Amir el 21 de Nov. de 2023
Comentada: Ganesh el 29 de Nov. de 2023
function newfypAmir
format long g
%Define all parameters
global Pr A C M K SS
M = 1;
K = 1;
A = 3;
C = -12;
Pr = 0.5;
SS = 0;
%Boundary layer thickness & stepsize
etaMin = 0;
etaMax1 = 15;
etaMax2 = 12; %15, 10
stepsize1 = etaMax1;
stepsize2= etaMax2;
%%%%%%%%%%%%%%%%%%%%%% First solution %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
options = bvpset('stats','off','RelTol',1e-10);
solinit = bvpinit (linspace (etaMin, etaMax1, stepsize1), @OdeInit1);
sol = bvp4c(@OdeBVP, @OdeBC, solinit, options);
eta = linspace (etaMin, etaMax1, stepsize1);
y = deval (sol, eta);
%Displaying the output for first solution
fprintf('\nFirst solution:\n');
fprintf('f" = %7.9f\n',y(3));
fprintf('f` = %7.9f\n',y(2));
fprintf('theta = %7.9f\n',y(4));
fprintf('\n');
%%%%%%%%%%%%%%%%%%%%%% Second solution %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
options = bvpset('stats','off','RelTol',1e-10);
solinit = bvpinit (linspace (etaMin, etaMax2, stepsize2), @OdeInit2);
sol = bvp4c (@OdeBVP, @OdeBC, solinit, options);
eta = linspace (etaMin, etaMax2, stepsize2);
y = deval (sol, eta);
%Displaying the output for second solution
fprintf('\nSecond solution:\n');
fprintf('f" = %7.9f\n',y(3));
fprintf('f` = %7.9f\n',y(2));
fprintf('theta = %7.9f\n',y(4));
fprintf('\n');
%Define the ODE function
function ff = OdeBVP(~, y, Pr, M, K, A, C, SS)
global Pr M K A C SS
ff = [
y(2)
y(3)
( y(2)*y(2) - y(1)*y(3) - K*(1-y(2)) - M*M*(1-y(2)) - 1 ) / Pr
y(5)
-1*y(1)*y(5)
];
%Define the boundary condition
function res = OdeBC(ya, yb, A, C, SS)
global A C SS
res = [
ya(1)-SS
ya(2)-C-A*ya(3)
ya(4)-1
yb(2)-1
yb(4)];
%Setting the initial guess for first solution
function v = OdeInit1 (~, A, C, SS)
global A C SS
v = [0.5
0
0
0
0];
%Setting the initial guess for second solution
function v1 = OdeInit2 (x, A, C, SS)
global A C SS
v1 = [exp(-x)
exp(-x)
exp(-x)
exp(-x)
exp(-x)];
  1 comentario
Ganesh
Ganesh el 29 de Nov. de 2023
Hi @Amir,
In the lines of code where you are printing the solution, you have printed y(2), y(3) and y(4), whereas y is a matrix.
Kindly ensure that you are trying to access the right matrix column.
Thank you,
Ganesh S

Iniciar sesión para comentar.

Respuestas (0)

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by