Solved

Can you simplify this mathematical algorithm

Posted on 2014-11-19
6
192 Views
Last Modified: 2014-11-20
Is it possible to refactor this mathematical algorithm to minimize the use of trigonometric functions?

input:
  z      :=  0 to ½PI
  Ma, Mb :=  0 to ∞
  Pa, Pb :=  0 to 2PI

algorithm:
  r = Ma * sin(Pa)
  i = Mb * sin(Pb)
  Sr = r + i
  Dr = r - i
  r = Ma * cos(Pa)
  i = Mb * cos(Pb)
  Si = r + i
  Di = r - i
  r = -cos(z)
  i = -sin(z)
  Tr = r * Si + i * Dr
  Ti = i * Si - r * Dr

output:
  Ra :=  Sr + Tr
  Ia :=  Ti + Di
  Rb :=  Sr - Tr
  RI :=  Ti - Di

Open in new window

0
Comment
Question by:JasonMewes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 40451983
What do Ra,Ia,Rb,RI represent?
Unless you can establish some relationship between the inputs, there may not be much more you can do than to reduce half of the trigonometric functions to sqrt functions.
Or if you can transform your inputs so that instead of working with Ma,Mb,Pa,Pb,
you're working with inputs that correspond to  Ma*sin(Pa),Ma*cos(Pa),Mb*sin(Pb),Mb*cos(Pb),
But that may depend on refactoring other parts of the algorithm that use this part.
0
 

Author Comment

by:JasonMewes
ID: 40452008
Errors (for reference, no effect on question/solution):
Line 3 - bounds are actually -∞ to +∞
Line 24 - the name RI is actually Ib

Ra, Ia, Rb, Ib represent the four needed outputs of the algorithm.
There is no relationship between the inputs, only the bounds stated.

Other parts cannot be refactored, as inputs are external and outputs at this stage must be as specified.

SQRT is costlier than SIN and COS in this case.

Essentially you are saying that this is already as optimized as it can get?
Not possible to use identities or relationships (such as sin(A + B) = sin(A)*cos(B) + cos(A)*sin(B)) to reduce?
Given your (ozo) track record I trust your opinion implicitly!
0
 

Author Comment

by:JasonMewes
ID: 40452018
This probably does not help:

Ma, Pa = magnitude, phase pair A
Mb, Pb = magnitude, phase pair B

Ra, Ia = complex number out A
Rb, Ib = complex number out B
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 84

Expert Comment

by:ozo
ID: 40452126
I'm not sure if this comes out simpler, but
Tr = -(Ma * cos(z-Pa) + Mb * cos(z+Pb))
Ti = -(Ma * sin(z-Pa) + Mb * sin(z+Pb))
0
 

Author Comment

by:JasonMewes
ID: 40452169
Since Sr and Di (requiring four sin/cos to calculate) are still required to calculate output - it seems calculating Tr and Ti this way would add additional processing.
0
 
LVL 16

Expert Comment

by:dhsindy
ID: 40452943
This page shows a history of how trig functions have been computed in the past and how complicated it becomes.  If you read this you will probably be convinced to just use the functions defined in program.  That is probably the simplest way.

http://www.clarku.edu/~djoyce/trig/compute.html
0

Featured Post

 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
This article provides a brief introduction to tissue engineering, the process by which organs can be grown artificially. It covers the problems with organ transplants, the tissue engineering process, and the current successes and problems of the tec…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Suggested Courses

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question