Numerical Solution of Trigonometric Equation
Numerical Solution of Trigonometric Equation
(OP)
I have a formula;
y = A÷cos(x) + B*sin(x)
Is there a download (VB savant I am not) that will solve for x when varying y? A & B are constants.
Thank-you for your help.
y = A÷cos(x) + B*sin(x)
Is there a download (VB savant I am not) that will solve for x when varying y? A & B are constants.
Thank-you for your help.





RE: Numerical Solution of Trigonometric Equation
I2I
RE: Numerical Solution of Trigonometric Equation
=====================================
Eng-tips forums: The best place on the web for engineering discussions.
RE: Numerical Solution of Trigonometric Equation
RE: Numerical Solution of Trigonometric Equation
corus
RE: Numerical Solution of Trigonometric Equation
RE: Numerical Solution of Trigonometric Equation
corus
RE: Numerical Solution of Trigonometric Equation
B^2*C^4+(y^2-B^2)*C^2-2*C*y*A+A^2 = 0
But that equation does not have any simple analytical solution. Maple didn't quite take 141 pages, but it is an ugly result that is waaaay to cumbersome to work with (unless you want to leave it in Maple or whatever symbolic program you're using).
=====================================
Eng-tips forums: The best place on the web for engineering discussions.
RE: Numerical Solution of Trigonometric Equation
Isn't the solution space of x effectively limited to 0 to 2*pi?
Y*cos(x)-A-B*sin(x)*cos(x)=0
Doesn't look hard does it?
Cheers
Greg Locock
Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
RE: Numerical Solution of Trigonometric Equation
y1 = A/Cos(x) ; x = acos(A/y1)
y2 = B*sin(x) ; x = asin(y2/B)
y = y1 + y2
Three equations, three unknowns. Should be solvable (although I can't do it).
RE: Numerical Solution of Trigonometric Equation
Y*cos(x)-A-B*sin(x)*cos(x)
set up a column of x 0, 0.01 ...6.29
set up the above equation in the second column
x is a solution when that is zero.
square the second column, find its minimum (MIN)
Look up the corresponding x value with VLOOKUP
call this x0
set up a refined range for x about x0, using steps of 0.0001
shampoo, rinse and repeat to any arbitrary limit of accuracy.
I warned you it was nasty.
Cheers
Greg Locock
Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
RE: Numerical Solution of Trigonometric Equation
By inspection, a solution for the case y=A is cos(x)=1.
If this is maths homework then to get top marks just say that the solution is trivial. They'll think you're a genius, believe me.
corus
RE: Numerical Solution of Trigonometric Equation
[arctan((y*(1/6*3^(1/2)/B*((-2*(18....)^(1/2))^(1/2))],
[arctan((y*(-1/6*3^(1/2)/B*((-2*(18....)^(1/2))^(1/2))],
[arctan((y*(-1/6*3^(1/2)/B*((-2*(18....-16*B^2*A^4+8*A^2
RE: Numerical Solution of Trigonometric Equation
corus
RE: Numerical Solution of Trigonometric Equation
=====================================
Eng-tips forums: The best place on the web for engineering discussions.
RE: Numerical Solution of Trigonometric Equation
Cheers,
Joerd
Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
RE: Numerical Solution of Trigonometric Equation
I2I
RE: Numerical Solution of Trigonometric Equation
http://www.bmsltd.ie/Excel/Default.htm
MAY yeild a result between -1.56 and -1.58.
use any constant for A and B.
good luck!
-pmover
RE: Numerical Solution of Trigonometric Equation
Newton-Rhapson is one numerical method. There is also excel's solver, and Maple's fsolve, and I'm sure there are plenty more out there.
=====================================
Eng-tips forums: The best place on the web for engineering discussions.
RE: Numerical Solution of Trigonometric Equation
I2I
RE: Numerical Solution of Trigonometric Equation
RE: Numerical Solution of Trigonometric Equation
"The Microsoft Excel Solver tool uses the Generalized Reduced Gradient (GRG2) nonlinear optimization code developed by Leon Lasdon, University of Texas at Austin, and Allan Waren, Cleveland State University."
I'm not overly concerned about the algorithm as long as I get an answer. Then I do a sanity check on the answer myself.
=====================================
Eng-tips forums: The best place on the web for engineering discussions.
RE: Numerical Solution of Trigonometric Equation
A numerical approach is the obvious solution.
--------------------
How much do YOU owe?
http://www.brillig.com/debt_clock/
--------------------
RE: Numerical Solution of Trigonometric Equation
I2I
RE: Numerical Solution of Trigonometric Equation
Option Explicit
Sub FindRoot()
' Subroutine to find root of equation using Newton Raphson iteration
Dim Pi As Double, A As Double, B As Double, Y As Double, Ans As Double, Check As Double
Dim FirstRow As Long, FinalRow As Long, NPts As Long, I As Long
Pi = 3.14159265358979
' Figure out how many points there are to compute
FinalRow = Range("A65536").End(xlUp).Row
FirstRow = 10
NPts = FinalRow - FirstRow + 1
' constants
For I = 1 To NPts
' Constants A and B are in first and second column, respectively
A = Cells(FirstRow + I - 1, 1).Value
B = Cells(FirstRow + I - 1, 2).Value
' Target Y value for function A/cos(x)+B*sin(x) is in column 3.
Y = Cells(FirstRow + I - 1, 3).Value
' Zero out 'x'==Ans and check value, Check
Ans = 0#
Check = 0#
Ans = NRFunction(A, B, Y)
Check = Y - gfunc(Ans, A, B, Y, A, A)
' Print out answer "x" in 4th column, Check value of function is in 5th column.
' ///////////////////////////////// OUTPUT ///////////////////////////////////////
Cells(FirstRow + I - 1, 4).Value = Ans
Cells(FirstRow + I - 1, 5).Value = Check
Next I
' ///////////////////////////////// OUTPUT ///////////////////////////////////////
End Sub
Function NRFunction(A As Variant, B As Variant, C As Variant) As Double
' send in Y as the value of function
Dim g As Double, dg As Double, C1 As Double, C2 As Double
Dim tol As Double, err As Double, xnew As Double, Pi As Double
Dim iter As Long
Pi = 3.14159265358979
tol = 0.000001
' Some constants that may or may not be needed.
C1 = 0# 'if needed
C2 = 0# 'if needed
' Starting value. Depending on function, may have to be very close to the root you are seeking.
xnew = Pi / 4#
err = 10000000000#
iter = 1
Do While err > tol
g = gfunc(xnew, A, B, C, C1, C2)
dg = dgfunc(xnew, A, B, C, C1, C2)
xnew = xnew - g / dg
err = Abs(g / dg) / Abs(xnew + g / dg) 'scales the error
iter = iter + 1
Loop
NRFunction = xnew
End Function
Function gfunc(x As Variant, A As Variant, B As Variant, C As Variant, C1 As Variant, _
C2 As Variant) As Double
gfunc = C - (A / Cos(x) + B * Sin(x))
End Function
Function dgfunc(x As Variant, A As Variant, B As Variant, C As Variant, C1 As Variant, _
C2 As Variant) As Double
dgfunc = -(A * Sin(x) / (Cos(x) * Cos(x)) + B * Cos(x))
End Function
RE: Numerical Solution of Trigonometric Equation
corus
RE: Numerical Solution of Trigonometric Equation
RE: Numerical Solution of Trigonometric Equation