Code covered by the BSD License  

Highlights from
GoalFind

2.0

2.0 | 1 rating Rate this file 0 Downloads (last 30 days) File Size: 2.12 KB File ID: #25465

GoalFind

by Keith Sudheimer

 

01 Oct 2009

Do the opposite of any single variable function or transformation

| Watch this File

File Information
Description

Say you have a really nice function that transforms an input value into a output value. Now say you want to the opposite transformation. You can either go back and redo all of the math to reverse the transformation, or you can be lazy and use GoalFind. Here is a silly example sqrt(144) = 12. sqrt(?) = 10.

GoalFind('sqrt(N)',10,1000,2, 1, 1)

The arguments that go in are:
1. the formula ex. 'sqrt(N)'
2. the goal ex. 10
3. the maxium value you expect
4. the minimum value you expect
ex. I think the sqrt(?)=10 where ? is less than 1000 and greater than 2
5. how long in (seconds) can matlab work before you run out of patients
ex. 1 (work for a max of 1 second)
6. toggle printing the formula
ex. 1 will print to screen 'sqrt(100)=10' a 0 argument will print nothing.

MATLAB release MATLAB 7.9 (2009b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
03 Oct 2009 Jan Simon

It works, it has a help text (but not at the usual location) and some comments, but no H1-line.
Mathematically, the algorithm is weak: The formula is calculated at 1000 equidistant steps of the allowed interval. Then one point with the smalles difference to the wanted value is picked out and the new interval is limited to the mean of this point and the old interval limits. The check of reaching the goal does not consider a tolerance, but checks for equality.
This strategy can fail e.g. for periodical values (SIN, COS) and the choice of the new limits is more or less arbitrary. There are much better methods to find a solution of the function F(x) - y = 0, e.g. Matlab's FZERO, FMINBND. Using the processing time as termination criterion effects a randomness of the result, especially if TIC/TOC is used to measure the time: The result depends on the procesor speed and the activity of background processes! The number of iterations is better to create reproducible results.
Using anonymous functions or function handles as input is better than defining the function as string and replacing all 'N' - what will happen for the function 'mySIN(N)' ?!

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
reverse functions functions Keith Sudheimer 02 Oct 2009 11:28:06

Contact us at files@mathworks.com