same value for first and second solution
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Ganesh
le 29 Nov 2023
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
Réponses (0)
Voir également
Catégories
En savoir plus sur Calculus dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!