Asked by Zeyad Elsayed
on 10 Apr 2019

I am trying to find a finite number of solutions to an equation with infinite solutions, I am not really sure how to approach this problem.

cos(x)*cosh(x) = 1

In the equation above, there are infinite number of soluions for x. How should I write the code to get the first 5 solutions?

Answer by Torsten
on 11 Apr 2019

Accepted Answer

fun = @(x)cos(x)*cosh(x)-1;

Interval = zeros(4,2);

Interval(1,:) = [3/2*pi, 3/2*pi+0.5];

Interval(2,:) = [5/2*pi, 5/2*pi-0.5];

Interval(3,:) = [7/2*pi, 7/2*pi+0.5];

Interval(4,:) = [9/2*pi, 9/2*pi-0.5];

sol = zeros(5,1);

for i = 1:4

sol(i+1) = fzero(fun,Interval(i,:))

end

Sign in to comment.

Answer by John D'Errico
on 10 Apr 2019

Provably getting the FIRST 5 solutions is essentially impossible on a completely general function, as it is trivial to write a function that no general solver that will treat your function as a black box can ever solve.

Even getting 5 solutions can be difficult, since even for a problem with infinitely many solutions in theory, they may lie arbitrarily far out, and at entirely arbitrary locations.

Extracting solution loci from a graph is trivial. You look at the graph. Write down the approximate locations observed. Then start fzero at those points. If you want to do that automatically, it is less trivial, since any automatic algorithm on a general black box problem will be potentially breakable, that is, if you understand the algorithm and you want to break it.

But nothing stops you from a simple search. look for zero crossings.

The problem with a function like cos(x)*cosh(x) -- 1 is things will go to hell numerically, since cosh(x) will go to infinity exponentially fast. So you will then need to locate points where cox(x) is very near zero, and do so very accurately.

Anyway, it is trivial to locate approximate solutions to this. You just need to understand that most of the solutions will lie near roots of the function cos(x). (THINK ABOUT IT!)

Telling you more than that is equivalent to doing your homework though, and this is so clearly homework that giving you code is very much inappropriate on this forum.

Zeyad Elsayed
on 10 Apr 2019

Hi John D'Errico,

First of all I appreciate you spending the time to provide an explanation to my question.

However, this is not a homework assignment (however simple my question may seem to you). I was actually trying to solve an equation provided by a book on vibrations in mechanical engineering, and as you may know, in vibration there is something called normal modes, which can have infinite solutions (hence my question). The values of the roots of this equation cos(x)*cosh(x)-1, are actually provided in the book. But I wanted to check the values in the book by trying it myself on matlab. As I am not very familiar with the software and I am in the process of trying to learn it, I actually thought Mahmoud asking for the code was really helpful, as I tried to follow the steps provided by Mathworks online and I couldn't do it.

Anyways, thanks to everyone for the help!

John D'Errico
on 11 Apr 2019

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## Torsten (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/455508-how-to-solve-an-equation-with-infinite-solutions-to-find-only-n-number-of-solutions#comment_692205

## Mahmoud Sayed (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/455508-how-to-solve-an-equation-with-infinite-solutions-to-find-only-n-number-of-solutions#comment_692472

## John D'Errico (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/455508-how-to-solve-an-equation-with-infinite-solutions-to-find-only-n-number-of-solutions#comment_692475

Sign in to comment.