Checking Conditions on Multiple-Variable Functions
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
S H
am 13 Jan. 2019
Kommentiert: Jeff Miller
am 14 Jan. 2019
I have defined a few functions f1, f2, f3, f4, ... They depend on the same multiple variables x, y, z, u, v, ... Each of these variables are defined over a range of real numbers. From these ranges, I want to find a data set that satisfies various conditions such as f1 becomes minimum, f2 becomes maximum, f3 becomes a poisitve real number with no imaginary, f4 stays limited to a range, ...
I can write this code discretely by defining a grid matrix created by variables and then finding the values of all functions at all grid points and finally apply the conditions and selecting the dataset using indexing. But this method becomes extremely slow because to get accurate results, long variable points must be created that exponentially increase the number of grid points and memory.
Could you show me a code that does the job using functions? Are there options that can be applied to this code for faster and more accurate solutions?
0 Kommentare
Akzeptierte Antwort
Jeff Miller
am 13 Jan. 2019
Try fminsearch. Write a global error function to sum up the deviations from all conditions you want to satisfy, and fminsearch will try to minimize that function. Your function might look something like this:
error = f1 + (-f2) + abs(imag(f3)) + ...
2 Kommentare
Jeff Miller
am 14 Jan. 2019
- You can use some constants to adjust the relative importance of the different function values, something like this: error = f1 + (-f2)/1000 + abs(imag(f3)) It may take some trial and error to find the right adjustments for your problem.
- No idea what's going on with the function_handle error. Based on your initial post, I was assuming that f3 returned a value with both real and imaginary parts, and imag(f3) should then give you the size of the imaginary part.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!