필터 지우기
필터 지우기

same value for first and second solution

조회 수: 3 (최근 30일)
Amir
Amir 2023년 11월 21일
댓글: Ganesh 2023년 11월 29일
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
Ganesh
Ganesh 2023년 11월 29일
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

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by