How to solve for the first five values only?
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have an equation: cos(x)cosh(x)+1=0
There are infinitely many solutions to x but I only want the first five(only positive x's). I've messed around with fnzeros but I can't seem to make it work.
0 comentarios
Respuestas (1)
Star Strider
el 9 de Feb. de 2017
See if this does what you want:
f = @(x) cos(x) .* cosh(x) + 1;
for k1 = 1:500
s(k1) = fzero(f, k1/10);
end
su = unique(round(abs(s), 5));
Output = su(1:5)
Output =
1.8751 4.6941 7.8548 10.996 14.137
2 comentarios
Star Strider
el 9 de Feb. de 2017
My pleasure.
First, ‘f’ is an anonymous function version of your expression. See the relevant sections of the documentation on Function Basics (link) for details. It is necessary in order to use the fzero function.
Second, the for loop is just a brute-force method of finding the various zero-crossings. Many are duplicates (or nearly so, considering the default tolerances in fzero), so it is necessary to use the round function (here to 5 decimal places) to truncate them to provide actual unique values. (The uniquetol function is an alternate option, and would not require round in the input.)
Third, the ‘Output’ assignment simply selects the first 5 positive values.
Ver también
Categorías
Más información sobre Spline Postprocessing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!