How to get the answer from the following code. How can i extract the values from the code?

1 view (last 30 days)
%I have the following non-linear coupled ODE'S
%u"+(Nt*G1*u')+(M1*G2*h')+(R1*u)+(G3*GT*Theta)+(G4*GC*Phi)=0,
%(1+iHc)*G5*h"+u'+Nt*Pm*h'=0,
%T"+(Nt*Pr*G6)*T'-(S1*Pr*G7*T)=0;
%C"+(Nt*Sc*G8*C')-(Hp*Sc*G8*C)=0;
% Boundary conditions: u=1, h=1,T'=G7*B1*(T-1),C'=G8*F1*(C-1) at y=0.
% u',h',T,C = 0 at y tends to infinity.
clc
B1 = 0.5;
F1 = 0.5;
k = 0.3;
RO = 0.5;
Hp = 0.2;
M1 = 16;
Nt = 0.15;
Pr = 6.2;
Pm = 0.7;
S1 = 1;
P1 = 0.02;
P2 = 0.0;
Sc = 0.78;
Hc = 0.5;
GT = 4;
GC = 5;
e1 = (1./(((1-P1).^2.5).*((1-P2).^2.5)));
Ros1 = 4420;
Ros2 = 5180;
Rof = 997.1;
Ro1 = (Ros1./Rof);
Ro2 = (Ros2./Rof);
e2 = ((1-P2).*((1-P1)+(P1.*Ro1)))+(P2.*Ro2);
Betas1 = 0.000058;
Betas2 = 0.000013;
Betaf = 0.00021;
Beta1 = ((Ros1.*Betas1)./(Rof.*Betaf));
Beta2 = ((Ros2.*Betas2)./(Rof.*Betaf));
e3 = ((1-P2).*((1-P1)+(P1.*Beta1)))+(P2.*Beta2);
BetaCs1 = 0.006;
BetaCs2 = 0.45;
BetaCf = 1;
BetaC1 = ((Ros1.*BetaCs1)./(Rof.*BetaCf));
BetaC2 = ((Ros2.*BetaCs2)./(Rof.*BetaCf));
e4 = ((1-P2).*((1-P1)+(P1.*BetaC1)))+(P2.*BetaC2);
sigmas1 = 580000;
sigmas2 = 25000;
sigmaf = 0.005;
sigma = (sigmas1./sigmaf);
d5 = (((1+2.*P1)+(2.*(1-P1).*(1./sigma)))./((1-P1)+((2+P1).*(1./sigma))));
e5 = d5.*(((sigmas2.*(1+2.*P2))+(2.*d5.*sigmaf.*(1-P2)))./((sigmas2.*(1-P2))+(d5.*sigmaf.*(2+P2))));
Cps1 = 0.56;
Cps2 = 670;
Cpf = 4179;
RoCp1 = ((Ros1.*Cps1)./(Rof.*Cpf));
RoCp2 = ((Ros2.*Cps2)./(Rof.*Cpf));
e6 = ((1-P2).*((1-P1)+(P1.*RoCp1)))+(P2.*RoCp2);
Ks1 = 7.2;
Ks2 = 9.7;
Kf = 0.613;
K = (Kf./Ks1);
d7 = (((1+2.*P1)+(2.*(1-P1).*K))./((1-P1)+((2+P1).*K)));
e7 = d7*((((Ks2+2.*d7.*Kf)+(2.*d7.*Kf))+(2.*P2.*(Ks2-d7.*Kf)))./((Ks2+2.*d7.*Kf)-(P2.*(Ks2-d7.*Kf))));
e8 = ((1-P1).*(1-P2));
G1 = (e2./e1);
G2 = (1./e1);
G3 = (e3./e1);
G4 = (e4./e1);
G5 = (1./e5);
G6 = (e6./e7);
G7 = (1./e7);
G8 = (1./e8);
dydx = @(x,y)[y(5);
y(6);
y(7);
y(8);
-(Nt.*Pr.*G6.*y(5))+(S1.*Pr.*G6.*y(1));
-(Nt.*Sc.*G8.*y(6))+(Hp.*Sc.*G8.*y(2));
-(Nt.*G1.*y(7))-(M1.*G2.*y(8))-(((2.*1i.*RO.*G1)-(1./k)).*y(3))-(GT.*G3.*y(1))-(GC.*G4.*y(2));
-((y(7)./((1+1i.*Hc).*G5)))-((Nt.*Pm.*y(8))./((1+1i.*Hc).*G5))];
BC1 = @(ya,yb)[(ya(5)-G7.*B1.*(ya(1)-1));yb(1);
(ya(6)-G8.*F1.*(ya(2)-1));yb(2);
ya(3)-1;yb(7);
ya(4)-1;yb(8)];
yinit = [0.1;0.1;0.1;0.1;0.1;0.1;0.1;0.1];
solinit = bvpinit(linspace(0,2,50),yinit);
options = bvpset('AbsTol',1e-3,'RelTol',1e-3,'stats','off','Nmax',1000);
U1 = bvp4c(dydx,BC1,solinit,options);
I need to find the following
F = ((du/dy)-Nt*(d^2u/dy^2)) at y=0,J = -(i*(dh/dy)) at y=0,
N1 = -(dT/dy) at y=0, N2 = -(dC/dy) at y=0.
  1 Comment
Umar
Umar on 1 Oct 2024
Hi @ sunitha kolasani,
Please let us know if you need further assistance or clarification regarding code, we will be more happy to help you out.

Sign in to comment.

Accepted Answer

Torsten
Torsten on 1 Oct 2024
Edited: Torsten on 1 Oct 2024
F = U1.y(5,1)-Nt*U1.yp(5,1)
J = -1i*U1.y(6,1)
N1 = -U1.y(7,1)
N2 = -U1.y(8,1)
  8 Comments
sunitha kolasani
sunitha kolasani on 2 Oct 2024
As you wrote, y(7,1) = u'(0) and yp(7,1) = u''(0). Thus F = u'(0)-Nt*u''(0) = U1.y(7,1)-Nt*U1.yp(7,1)
Check the other equations similarly.
yes sir. in the above formate only.

Sign in to comment.

More Answers (1)

Umar
Umar on 1 Oct 2024

Hi @sunitha kolasani ,

You mentioned, “I need to find the following :F = ((du/dy)-Nt*(d^2u/dy^2)) at y=0,J = -(i*(dh/dy)) at y=0,N1 = -(dT/dy) at y=0, N2 = -(dC/dy) at y=0.”

So, you are trying to solve a set of non-linear coupled ordinary differential equations (ODEs) using MATLAB. The equations involve multiple variables and parameters, and you need to implement boundary conditions. Additionally, you want to compute specific derivatives at a boundary point and display the final results. In order to solve these given non-linear coupled ODEs in code provided by you, you will need to follow a structured approach which includes defining the system of equations, setting up the boundary conditions, and using MATLAB's built-in functions to find the solution. Below is the complete code with detailed comments explaining each step, along with the calculations for the required derivatives at ( y = 0 ).

% Define constants
B1 = 0.5;
F1 = 0.5;
k = 0.3;
RO = 0.5;
Hp = 0.2;
M1 = 16;
Nt = 0.15;
Pr = 6.2;
Pm = 0.7;
S1 = 1;
P1 = 0.02;
P2 = 0.0;
Sc = 0.78;
Hc = 0.5;
GT = 4;
GC = 5;
% Calculate parameters
e1 = (1./(((1-P1).^2.5).*((1-P2).^2.5)));
Ros1 = 4420;
Ros2 = 5180;
Rof = 997.1;
Ro1 = (Ros1./Rof);
Ro2 = (Ros2./Rof);
e2 = ((1-P2).*((1-P1)+(P1.*Ro1)))+(P2.*Ro2);
Betas1 = 0.000058;
Betas2 = 0.000013;
Betaf = 0.00021;
Beta1 = ((Ros1.*Betas1)./(Rof.*Betaf));
Beta2 = ((Ros2.*Betas2)./(Rof.*Betaf));
e3 = ((1-P2).*((1-P1)+(P1.*Beta1)))+(P2.*Beta2);
BetaCs1 = 0.006;
BetaCs2 = 0.45;
BetaCf = 1;
BetaC1 = ((Ros1.*BetaCs1)./(Rof.*BetaCf));
BetaC2 = ((Ros2.*BetaCs2)./(Rof.*BetaCf));
e4 = ((1-P2).*((1-P1)+(P1.*BetaC1)))+(P2.*BetaC2);
sigmas1 = 580000;
sigmas2 = 25000;
sigmaf = 0.005;
sigma = (sigmas1./sigmaf);
d5 = (((1+2.*P1)+(2.*(1-P1).*(1./sigma)))./((1-P1)+((2+P1).*(1./sigma))));
e5 = d5.*(((sigmas2.*(1+2.*P2))+(2.*d5.*sigmaf.*(1-P2)))./((sigmas2.*(1-P2))+
(d5.*sigmaf.*(2+P2))));
Cps1 = 0.56;
Cps2 = 670;
Cpf = 4179;
RoCp1 = ((Ros1.*Cps1)./(Rof.*Cpf));
RoCp2 = ((Ros2.*Cps2)./(Rof.*Cpf));
e6 = ((1-P2).*((1-P1)+(P1.*RoCp1)))+(P2.*RoCp2);
Ks1 = 7.2;
Ks2 = 9.7;
Kf = 0.613;
K = (Kf./Ks1);
d7 = (((1+2.*P1)+(2.*(1-P1).*K))./((1-P1)+((2+P1).*K)));
e7 = d7*((((Ks2+2.*d7.*Kf)+(2.*d7.*Kf))+(2.*P2.*(Ks2-
d7.*Kf)))./((Ks2+2.*d7.*Kf)-
(P2.*(Ks2-d7.*Kf))));
e8 = ((1-P1).*(1-P2));
G1 = (e2./e1);
G2 = (1./e1);
G3 = (e3./e1);
G4 = (e4./e1);
G5 = (1./e5);
G6 = (e6./e7);
G7 = (1./e7);
G8 = (1./e8);
% Define the system of ODEs
dydx = @(x,y)[y(5);
            y(6);
            y(7);
            y(8);
            -(Nt.*Pr.*G6.*y(5))+(S1.*Pr.*G6.*y(1));
            -(Nt.*Sc.*G8.*y(6))+(Hp.*Sc.*G8.*y(2));
            -(Nt.*G1.*y(7))-(M1.*G2.*y(8))-(((2.*1i.*RO.*G1)-(1./k)).*y(3))-
             (GT.*G3.*y(1))-(GC.*G4.*y(2));
            -((y(7)./((1+1i.*Hc).*G5)))-((Nt.*Pm.*y(8))./((1+1i.*Hc).*G5))];   
% Define boundary conditions
BC1 = @(ya,yb)[(ya(5)-G7.*B1.*(ya(1)-1)); yb(1);
             (ya(6)-G8.*F1.*(ya(2)-1)); yb(2);
             ya(3)-1; yb(7);
             ya(4)-1; yb(8)];
% Initial guess for the solution
yinit = [0.1; 0.1; 0.1; 0.1; 0.1; 0.1; 0.1; 0.1];
solinit = bvpinit(linspace(0, 2, 50), yinit);
% Set options for the solver
options = bvpset('AbsTol', 1e-3, 'RelTol', 1e-3, 'stats', 'off', 'Nmax', 1000); 
% Solve the boundary value problem
U1 = bvp4c(dydx, BC1, solinit, options);
% Extract the solution at y = 0
:y_at_0 = U1.y(:, 1);
% Calculate the required derivatives at y = 0
F = (y_at_0(5) - Nt * (U1.y(5, 1) - U1.y(5, 2))) % F = (du/dy) - Nt*(d^2u/dy^2)
J = -1i * (y_at_0(6)); % J = -(i*(dh/dy))
N1 = -1 * (U1.y(3, 1)); % N1 = -(dT/dy)
N2 = -1 * (U1.y(4, 1)); % N2 = -(dC/dy)
% Display the final results
fprintf('Results at y = 0:\n');
fprintf('F = %.4f\n', F);
fprintf('J = %.4f\n', J);
fprintf('N1 = %.4f\n', N1);
fprintf('N2 = %.4f\n', N2);

Please see attached.

So, the above modified code snippet of yours begins by defining all the necessary constants and parameters required for the equations. The function dydx defines the system of ODEs based on the provided equations. Each equation corresponds to a specific variable,and function BC1 specifies the boundary conditions for the problem, ensuring that the solution adheres to the specified constraints at both ends of the interval. An initial guess for the solution is provided, and the bvp4c function is used to solve the boundary value problem with specified options. After solving, the solution at ( y = 0 ) is extracted, and the required derivatives ( F ), ( J ), ( N1 ), and ( N2 ) are calculated. Finally, the results are printed to the console for review. Please see attached.

Please let me know if you have any further questions.

  4 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!