Suppose I need to solve a system of equations such as
ax + by + c = 0
(a/x)^2 + (b/y)^2 - d^2 = 0
where (x, y) are the variables to solve for, and (a, b, c, d) are all input parameters.
The function fsolve allows only guess values of (x, y) to be passed, e.g. result = fsolve(@f, [1;-1]), where f is the function containing those two equations.
If values of (a, b, c, d) change, the function f needs to know and solve accordingly.
One proven way is to define (a,b,c,d) as global parameters. However, if (a,b,c,d) are rather localized parameters, it is strange to define them as global parameters. It would be best if they could somehow be passed into function f without being defined as global parameters.
Can this be done?
I have tried using a nested function, i.e. pass the guess values of (x, y) AND the parameters (a,b,c,d) into a parent function. Inside it is nested function defining the equations, for example:
function result = parent(x,y,a,b,c,d)
result = fsolve(@f, [1;-1]);
function res = f(z)
res(1) =...; res(2) =...;
But calling the nested function with a function handle @f is not supported.
Any help is much appreciated! Thanks!