Refer to an anonymous equation within the function for the fsolve() method
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I would like to define a global anonymous equation and refer to it within my external function which I use for the fsolve() method.
This are my two files (This is just a minimal working example of a bigger project):
fsolve_test_1.m
firstGuess = [1;
1;
1];
ate = @(x,y) x + y; %%%%%%%%%%%ate for 'anonymous test equation'
[x, fval] = fsolve(@fsolve_test_1_function_1, firstGuess)
and fsolve_test_1_function_1
function F = fsolve_test_1_function_1( x )
F = [3 * x(1) * x(2) + x(2) - x(3) - 12;
x(1) + x(2) * x(1) * x(1) + x(3) - 12;
x(1) - x(2) - x(3) + ate(5,6)]; %%%%%%%%%%%Here I want to call the defined ate() equation with random parameters
end
This gives me the following error code:
Undefined function or variable 'ate'.
Error in fsolve_test_1_function_1 (line 5)
x(1) - x(2) - x(3) + ate(5,6)];
Error in fsolve (line 230)
fuser = feval(funfcn{3},x,varargin{:});
Error in fsolve_test_1 (line 7)
[x, fval] = fsolve(@fsolve_test_1_function_1, firstGuess)
So, what would be the correct way to use the anonymous equation in this case?
Thank you and enjoy your day!
0 Kommentare
Antworten (1)
Steven Lord
am 25 Apr. 2017
Don't make it global; that gives anyone with access to the global workspace (so any function that you run in your MATLAB session) the ability to change the problem you're solving. Instead, pass it into the function as an additional parameter using one of the techniques given in this section of the documentation.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Fluid Dynamics 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!