- Plot the graph for f(x)=cos(x)*cosh(x)-1
- Extract five intervals from the graph in which the first 5 zeros are located.
- Call "fzero" five times with these intervals as initial x0.
How to solve an equation, with infinite solutions, to find only n number of solutions?
25 次查看(过去 30 天)
显示 更早的评论
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?
3 个评论
Mahmoud Sayed
2019-4-10
I have been having trouble with the same thing here , Torsten can you please explain how you do number 2 (extracting the points from the graph) as well as step 3 which is calling fzero I cant quite understand how to execute that on MATLAB, thanks a lot!
John D'Errico
2019-4-10
编辑:John D'Errico
2019-4-10
Mahmoud - please don't hijack this problem, asking for code to solve it, as this problem is clearly a homework assignment. If you have a separate (real) specific problem that is not homework, then ask a question to that effect, and show what you have done, what is the problem, etc.
采纳的回答
Torsten
2019-4-11
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
0 个评论
更多回答(1 个)
John D'Errico
2019-4-10
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.
2 个评论
John D'Errico
2019-4-11
Of course, you are happy to see someone writing the code for you. You would have learned more had you actually tried it yourself, whether or not this is actually homework. Making an effort will get you further, and is the only way you will ever get a response from me again.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!