If else condition for each iteration in "FSOLVE"
2 views (last 30 days)
Show older comments
I want to implement a 'if statement' in every iteration of fsolve. In bellow code, b is a function x,y, and b comes from if else statement. How should I imlement it?
syms x y
a=atan2(x,y)
% condition to be implemented
if a<=0
b=x+y;
else
b=x-y;
end
fun =@(x,y) x^2 + y^2 + b; %function
x0=[0,0]; % [x,y]
out = fsolve(fun,x0)
Thanks in advance.
0 Comments
Answers (1)
Matt J
on 17 Nov 2021
Edited: Matt J
on 19 Nov 2021
That would create discontinuity in the function. fsolve is designed to solve problems with smooth, differentiable equation functions. You could, of course, invoke fsolve twice, once for b=1 and once for b=2. You could then check which solution satisfies the requirement on atan2(x,y).
0 Comments
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!