help me to find error in this file?

1 view (last 30 days)
Nk
Nk on 30 Jan 2023
Answered: the cyclist on 30 Jan 2023
function Needle1
a=0.2;
solinit= bvpinit(linspace(a,40,100),[0 0 0]);
sol = bvp4c(@Needle1ode,@Needle1bc,solinit);
eta = sol.x;
f = sol.y;
disp(f(3,1))
function dfdeta = Needle1ode(eta,~)
Pr=3.0;thetha=2.0;Nr=10;Ec=0.3;
dfdeta = [ f(2)
f(3)
-(1/(2*eta))*(f(1)*f(3)+2*f(3))
f(5)
-(f(5)/eta*(1+4/3*Nr*(f(4)*(thetha-1)+1)^3)+Pr*f(1)*f(5)/2*eta*(1+4/3*Nr*(f(4)*(thetha-1)+1)^3 +4*Ec*Pr*(f(3))^2/(1+4/3*Nr*(f(4)*(thetha-1)+1)^(3)+2*f(4)*(f(4)*(thetha-1)+1)^(3)/(3*eta*Nr)*(1+4/3*Nr*(f(4)*(thetha-1)+1)^3)+4*f(5)^2*(thetha-1)*(f(4)*(thetha-1)+1)^2/(Nr*(1+4/3*Nr(f(4)*(thetha-1)+1)^3
];
function res = Needle1bc(f0,finf)
a=0.2;e=0.3;
res = [f0(1)-(a*e/2)
f0(2)-e/2
finf(2)-(1-e)/2
f0(1)-1
finf(1)-0
];
error is in this line:
-(f(5)/eta*(1+4/3*Nr*(f(4)*(thetha-1)+1)^3)+Pr*f(1)*f(5)/2*eta*(1+4/3*Nr*(f(4)*(thetha-1)+1)^3 +4*Ec*Pr*(f(3))^2/(1+4/3*Nr*(f(4)*(thetha-1)+1)^(3)+2*f(4)*(f(4)*(thetha-1)+1)^(3)/(3*eta*Nr)*(1+4/3*Nr*(f(4)*(thetha-1)+1)^3)+4*f(5)^2*(thetha-1)*(f(4)*(thetha-1)+1)^2/(Nr*(1+4/3*Nr(f(4)*(thetha-1)+1)^3
];
and the error shown was;
>> Needle1
Error: File: Needle1.m Line: 16 Column: 309
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for
mismatched delimiters.

Accepted Answer

the cyclist
the cyclist on 30 Jan 2023
The error seems to be that you are missing parentheses, or they are otherwise mismatched. We could guess at where they are missing, but could not guarantee that the resulting expression is the one you need.
Rather than trying to find the error for you, I will suggest the following strategy for you to find the error yourself.
As you already can see, an expression like
-(f(5)/eta*(1+4/3*Nr*(f(4)*(thetha-1)+1)^3)+Pr*f(1)*f(5)/2*eta*(1+4/3*Nr*(f(4)*(thetha-1)+1)^3 +4*Ec*Pr*(f(3))^2/(1+4/3*Nr*(f(4)*(thetha-1)+1)^(3)+2*f(4)*(f(4)*(thetha-1)+1)^(3)/(3*eta*Nr)*(1+4/3*Nr*(f(4)*(thetha-1)+1)^3)+4*f(5)^2*(thetha-1)*(f(4)*(thetha-1)+1)^2/(Nr*(1+4/3*Nr(f(4)*(thetha-1)+1)^3
is very difficult to debug. The first thing I would do define smaller chunks of that expression, starting with terms that repeat frequently. For example, the subexpression
(f(4)*(thetha-1)+1)^3
appears several times, so perhaps define a variable
f4_theta = (f(4)*(thetha-1)+1)^3;
and use it in the longer expression. That will reduce the overall number of parentheses you are using, and make it easier to debug this monster statement.

More Answers (0)

Tags

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!