View This Site In Your Own Language

Solving Equation in Matlab


Solving Equation in Matlab

We will ‘solve’ built-in function to solve an equation.


Format of Solution:

syms variable1 variable2 variable3 … variableN
EQUATION = [equation1,equation2,equation3,…,equationN]
SOLUTION = solve(EQUATION,[variable1,variable2,variable3,…,variableN])




Example-1: Find the solution of following equation:
                    x^2+2x+3 = 0
Code:


                   clc; clear all; close all;
                   syms x
                   eqn = x^2+2*x+3 == 0;
                   soln = solve(eqn,x)
                   fprintf('%f\n',double(soln))

Example-2: Find the solution of following equation:
                    3*x+3*y = 3
                    2*x+6*y = -2

Code:

                    clc; clear all; close all;
                    syms x y
                    eqn = [3*x+3*y==3, 2*x+6*y==-2];
                    soln = solve(eqn,[x,y])
                    fprintf('%f\n%f\n',double(soln.x(1)),double(soln.y(1)))

I do not describe anything. If you feel any problem, please let me know.
Solving Equation in Matlab Solving Equation in Matlab Reviewed by Ikram on 9/25/2019 02:59:00 PM Rating: 5

No comments:

Powered by Blogger.