The roots for an equation containing tangent
Ältere Kommentare anzeigen
I'm going to find the roots of an equation containing tangent. like x*1.4 - atan(0.28*x)=37.5
I dont know how to write the code to find x in above equation.
1 Kommentar
James Tursa
am 4 Okt. 2020
You say "like". Is that your actual equation? Or is your actual equation something else?
Akzeptierte Antwort
Weitere Antworten (3)
Alan Stevens
am 5 Okt. 2020
0 Stimmen
If x*1.4 - atan(0.28*x)=37.5 is the equation then fixed point iteration will work.
Rewrite the equation as x(n+1) = (37.5+atan(0.28*x(n)))/1.4, use an initial guess for x, say, x(1) = 20, then use a while loop until x(n+1) and x(n) are the same (or within some tolerance).
3 Kommentare
Mia Finit
am 5 Okt. 2020
Mia Finit
am 5 Okt. 2020
Alan Stevens
am 6 Okt. 2020
The following is what I mean:
% Fixed point iteration
% If the equation is 1.4x - atan(0.28x) = 37.5 rearrange it as
% x = (37.5 + atan(0.28x))/1.4
tol = 1^-8; % Set desired tolerance
x = 20; % initial guess
flag = true; % Set to false when converged
while flag
xold = x;
x = (37.5 + atan(0.28*xold))/1.4;
if abs(x-xold)<tol
flag = false;
end
end
disp(x)
However, if you have a different equation in mind, you might have to manipulate it in a few different ways in order to find an arrangement that converges.
An alternative is to look up the Newton-Raphson method.
Bruno Luong
am 6 Okt. 2020
>> fzero(@(x) x*1.4 - atan(0.28*x) - 37.5, 0)
ans =
27.8165
2 Kommentare
Mia Finit
am 6 Okt. 2020
Image Analyst
am 7 Okt. 2020
I did it numerically rather than analytically or by using a function. So it's not exact but as close as you want to get. However there are optimization functions (seems like a lot of them) that may do the trick. I'm not very familiar with them, since I don't have the optimization toolboxes. There is a function fminsearch() you may want to study up on. Or lsqnonneg().
Milind Amga
am 8 Okt. 2020
0 Stimmen
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
