How to solve for a trigonometric equation

2 views (last 30 days)
I want to solve for x from the following equation;
0.7978 + 0.7978*tan^2(x) = (Hperson * (1 - 0.1591*tan^2(x)))/ Fdist
The Hperson and Fdist are known values or variables. For example if Hperson = 175, Fdist = 120. The x value returned should be approx 38.7 degrees.
Apologies if such a question has been answered before. But I couldnt find a solution. Thank you.

Accepted Answer

Star Strider
Star Strider on 18 Aug 2017
Rearrange the equation, then use fzero:
Hperson = 175;
Fdist = 120;
F = @(x) 0.7978 + 0.7978*tand(x).^2 - (Hperson * (1 - 0.1591*tand(x).^2)) / Fdist; % Create Implicit Expression
x_deg = fzero(F, 45) % Use ‘fzero’
x_deg =
38.69
  2 Comments
Sweptix
Sweptix on 18 Aug 2017
Edited: Sweptix on 18 Aug 2017
I dont understand the use of fzero here. why do we need it? Why cant we just use the F value?
Also following your code sample above, I tried executing the following formula:
Tan(21.75 - x_deg) = (Hperson - Hcamera)/Fdist
as
function [ Tilt, Hcamera] = FindTilt( Hperson, Fdist )
% The function returns the camera tilt and camera height
% given the Height of the person and working distance
F = @(x) 0.7978 + 0.7978*tand(x).^2 - (Hperson * (1 - 0.1591*tand(x).^2)) / Fdist; % Create Implicit Expression
x_deg = fzero(F, 45); % Use ‘fzero’
Tilt = x_deg;
G = @(Hcamera) tand(21.75 - x_deg) - (175 - Hcamera)/Fdist;
Hcamera
end
For the value of G, Undefined function or variable "Hcamera".
Star Strider
Star Strider on 18 Aug 2017
The fzero function solves the implicit version of your equation for ‘x’. ‘F’ and ‘G’ in your code are anonymous functions that fzero finds the root of that are nearest the initial estimate (if a real root exists in that region).
You have not provided a definition for ‘Hcamera’ in your function, and you have not passed it to your function as a parameter. Since you apparently want to solve for ‘Hcamera’, use fzero again, with an appropriate initial value:
Hc0 = 100;
Hcamera = fzero(G, Hc0);
and using your previous data for ‘Hperson’ and ‘Fdist’:
Hcamera =
211.55

Sign in to comment.

More Answers (0)

Categories

Find more on Matrix Computations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!