필터 지우기
필터 지우기

The roots for an equation containing tangent

조회 수: 1 (최근 30일)
Mia Finit
Mia Finit 2020년 10월 4일
답변: Milind Amga 2020년 10월 8일
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
James Tursa
James Tursa 2020년 10월 4일
You say "like". Is that your actual equation? Or is your actual equation something else?

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2020년 10월 5일
Assuming it's not your homework, try this:
x = linspace(0, 40, 10000);
y = x*1.4 - atan(0.28*x);
plot(x, y, 'b-', 'LineWidth', 2);
grid on;
yline(37.5, 'LineWidth', 2, 'Color', 'r');
diffs = abs(y - 37.5);
[minDiff, index] = min(diffs)
xCrossing = x(index)
caption = sprintf('y crosses 37.5 at x = %f', xCrossing);
title(caption, 'FontSize', 18);
xlabel('x', 'FontSize', 18);
ylabel('y', 'FontSize', 18);
xline(xCrossing, 'LineWidth', 2, 'Color', 'g');
  댓글 수: 4
Image Analyst
Image Analyst 2020년 10월 6일
Look:
x = 27.8147814781478
y = x*1.4 - atan(0.28*x)
and you'll see in the command window:
x =
27.8147814781478
y =
37.4975993926413
Didn't you want to know the value of x where y = 37.5? Because that's what we were all thinking. If not, explain it to someone else and let them write the question. Maybe it will be better understood by us if you do that.
Mia Finit
Mia Finit 2020년 10월 6일
Thank you so much for your support. That is not the answer of my question. but if someone wants to help me out, please dont give me the exact answer of that. I asked you that to help me out in order to improve my programming skill. So, please just tell me the way by which Ill be able to code myself.
Thank all of you.

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Alan Stevens
Alan Stevens 2020년 10월 5일
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
Mia Finit
Mia Finit 2020년 10월 5일
or maybe I havent got what you mean...
Alan Stevens
Alan Stevens 2020년 10월 6일
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
Bruno Luong 2020년 10월 6일
>> fzero(@(x) x*1.4 - atan(0.28*x) - 37.5, 0)
ans =
27.8165
  댓글 수: 2
Mia Finit
Mia Finit 2020년 10월 6일
Yeah. I did the same as you. But I was wondering that if it is not a correcct answer... So, i was looking for another straight forward way by which I can get an answer. But it seems it is a proper one... cause the other answer given by our friend (the one with a graph) is the same.... however, my equation is much more complicated and I was not sure of that. But now, I am sure that the way I pass through was the best.
Thank you for your support guys.
Of course I am looking forward for the answer given by other guys as well.
Thanks all.
Image Analyst
Image Analyst 2020년 10월 7일
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
Milind Amga 2020년 10월 8일
@Image Analyst
Could you please have a look at my code too?

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by