# fsolve with collocation (outside of the function)

3 views (last 30 days)
salman yazdani on 29 Jun 2019
Commented: salman yazdani on 29 Jun 2019
Consider the following problem. The problems solves the linear(and nonlinear) equation correctly
syms Y11 Y12
r=fsolve(@noneqih,[0 0 ]);
function F=noneqih(co)
Y11=co(1);Y12=co(2);
F=[Y11+Y12-3; Y11-Y12-1]
end
but if you want the values of F set outside of the function noneqih, you can not import them inside e.g the following problem dosnt work
syms Y11 Y12
Agg=[Y11+Y12-3; Y11-Y12-1];
r=fsolve(@noneqih,[0 0 ]);
function F=noneqih(co)
global Agg;
Y11=co(1);Y12=co(2);
F=Agg
end
the second problem is needed when you want to solve the equations arise from other procedures

Stephen Cobeldick on 29 Jun 2019
I doubt that symbolic and/or global variables are helping you... in the first example they don't seem to be doing anything anyway.
Why not just parameterize a normal MATLAB function?:
For example, simply create a function handle for Agg and pass that.
salman yazdani on 29 Jun 2019
Dear Stephen,
Thanks for your valuable help. The problem can be simplified as
Agg=@(co) [co(1)+co(2)-3; co(1)-co(2)-1];
r=fsolve(Agg,[0 0 ]);
and it can be solved easily. But there arise another problem. As I told, the Agg function is calculated from an algebraic equation so I can not define variables as co(1) co(2) etc. when using co=sym('co',[1 2]);
it results to co=[co1 co2] and the following program doesnt work!
Agg=@(co) [co1+co2-3; co1-co2-1];
r=fsolve(Agg,[0 0 ]);