Asked by HINA
on 8 Apr 2019

Hello everyone,

I am trying to solve the following function for the variable P by using ''feval'' , ''fsolve'' and ''fzero'' but unable to get the root or if get the solution it is zero while I am looking for a non-zero solution to this function. Are there better methods available?

I will highly appreciate if anyone guide me how to solve this function for a non-zero solution. (Important to note that function is of type F(P)=0). and P>0

F =

function_handle with value:

@(P)sin(sqrt(2.0).*sqrt(-P./(P.*1.34217728e+8-2.863311530666667e+15)).*4.096e+5).*cosh(sqrt(P).*1.0./sqrt(P.*6.7108864e+7-2.796202666666667e+15).*4.096e+5).*sqrt(-P./(P.*6.7108864e+7-2.796202666666667e+15)).*-8.192e+3+sqrt(2.0).*cosh(sqrt(2.0).*sqrt(P).*1.0./sqrt(P.*1.34217728e+8-2.863311530666667e+15).*4.096e+5).*sin(sqrt(-P./(P.*6.7108864e+7-2.796202666666667e+15)).*4.096e+5).*sqrt(-P./(P.*1.34217728e+8-2.863311530666667e+15)).*8.192e+3

Answer by Alex Mcaulley
on 8 Apr 2019

Accepted Answer

Try changing the interval

fplot(F,[0,1e7])

Then, you can use:

fzero(F,1e5)

ans =

9.6575e+05

Sign in to comment.

Answer by John D'Errico
on 8 Apr 2019

This is just a continuation of the last time the same question was asked, and answered.

There are other roots, but they lie out very far, on the order of 1e6 or 3e6. In fact, there are probably infinitely many roots as a guess, based on the plots I did.

A numerical rootfinder (like vpasolve, or fzero, for that matter) requires an initial guess at the solution. No guess, no answer. Since there are infinitely many solutions to this problem, if you give no guess at all, then a tool like vpasolve is at least nice enough to guess zero to start at. (I think that is the default.) This means it will find the solution at P==0, since that just happens to be a solution.

Other solvers, thus if you convert the expression to a function using matlabFunction, then you can use fzero or fsolve? These solvers REQUIRE a starting value. They will fail if none is provided. Sorry, but that is how things work.

Anyway, if you want to find other solutions than that at P==0, you need to tell the code where to start looking. The example I give is if you set a blind man down on the surface of the earth, and told him to find the lowest point in elevation. If you start him out in the vicinity of the Dead Sea, do you seriously expect him to wander around until he finds the bottom of the Marianas trench? In fact, he will find the bottom of the Dead Sea. Or, how about if you start him out in the Himalayas?

A solver NEEDS an intelligent start point. If you don't give it that, expect arbitrary garbage. What do you expect when you have a function with infinitely many solutions? Which one should it give you, since it will give you only one?

It is often a good idea to plot your function to gain some intelligence. But that is EXACTLY what I did the last time I answered your question.

HINA
on 8 Apr 2019

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 9 Comments

## Torsten (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/455088-numerical-solution-of-a-matlab-function#comment_691255

## HINA (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/455088-numerical-solution-of-a-matlab-function#comment_691262

## HINA (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/455088-numerical-solution-of-a-matlab-function#comment_691272

## Torsten (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/455088-numerical-solution-of-a-matlab-function#comment_691277

## HINA (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/455088-numerical-solution-of-a-matlab-function#comment_691280

## Torsten (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/455088-numerical-solution-of-a-matlab-function#comment_691282

## madhan ravi (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/455088-numerical-solution-of-a-matlab-function#comment_691285

## John D'Errico (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/455088-numerical-solution-of-a-matlab-function#comment_691287

## madhan ravi (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/455088-numerical-solution-of-a-matlab-function#comment_691288

Sign in to comment.