Solving Nonlinear Equations in Matlab: A Comprehensive Guide

Slide Note
Embed
Share

Explore the process of solving nonlinear algebraic equations using fzero and fsolve commands in Matlab. Understand the potential for no solution or multiple solutions, and learn how to convert equations into functions, define the functions, call the solver, and run the full code to find the roots of the system. Includes examples, visuals, and step-by-step instructions.


Uploaded on Sep 21, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Nonlinear Equations in Matlab Jake Blanchard University of Wisconsin - Madison

  2. Introduction Nonlinear algebraic equations are encountered in many scientific applications fzero will solve single equations Matlab s fsolve command can solve these Nonlinearity implies potential for No solution Multiple solutions You may need a pretty good guess at solution

  3. Model Problem + + = 2 2 2 5 7 40 x y x y + + = 2 2 3 4 2 28 x y x y

  4. Convert to Functions + + = 2 2 2 5 7 40 0 x y x y + + = 2 2 3 4 2 28 0 x y x y

  5. How Does fsolve work? This command finds the roots of systems of functions We supply a set of functions and Matlab will find all the independent variables such that all the functions are zero (or near- zero) Solution is iterative, so we must provide guess

  6. Define Functions function fcns=eqns(z) x=z(1); y=z(2); fcns(1)=x.^2+2*y.^2-5*x+7*y-40; fcns(2)=3*x.^2-y.^2+4*x+2*y-28; end Save this to a file called eqns.m

  7. Define Functions function fcns=eqns(z) x=z(1); y=z(2); fcns(1)=x.^2+2*y.^2-5*x+7*y-40; fcns(2)=3*x.^2-y.^2+4*x+2*y-28; end Save this to a file called eqns.m

  8. Calling the solver guess=[2 3]; result=fsolve(@eqns, guess) Or guess=[2 3]; [result, fval, exitflag, output] =fsolve(@eqns, guess)

  9. The Full Code function solveeqs() guess=[2 3]; [result, fval, exit, output]=fsolve(@eqns, guess); result fval eqns(guess) output end function fcns=eqns(z) x=z(1); y=z(2); fcns(1)=x.^2+2*y.^2-5*x+7*y-40; fcns(2)=3*x.^2-y.^2+4*x+2*y-28; end

Related