%fsolve demo %we'll solve the system of equations: %x^2 + 2*y^2 = 3 %y = 5*x^2 + 6*x + 1 x = linspace(-1.75, 1.75, 1000); y1 = ((3 - x.^2)./2).^(1/2); y2 = -1 * ((3 - x.^2)./2).^(1/2); y3 = 5.*x.^2 + 6.*x + 1; plot(x,y1,'b'); hold on plot(x,y2,'b'); plot(x,y3,'r'); %Here we are going to just use the default fsolve options. %If we did not need to pass in x, we could just solve: %fsolve(@myfun, y0) %But in older versions of MATLAB we have to put something in the %options field. %So, OPTIONS = OPTIMSET (with no input arguments) creates an options structure %OPTIONS where all the fields are set to []. %initial guess for the vector y, get one solution y0 = [1,1]; solution1 = fsolve(@myfun, y0, optimset) %initial guess for the vector y, get the other solution y0 = [-1, -1]; solution2 = fsolve(@myfun, y0, optimset) y0 = [-1,1]; solution3 = fsolve(@myfun, y0, optimset) plot(solution1(1),solution1(2),'go'); plot(solution2(1),solution2(2),'mo'); plot(solution3(1),solution3(2),'go');