Brief hints in Matlab: Solving non-linear equations

Поділитися
Вставка
  • Опубліковано 14 жов 2024
  • #Machine_Theory #Mechanical_Engineering #Bachelor_of_Engineering #shorts #matlab #Mechanical_Principles #applied_mathematics #numerical #numerical_analysis
    In this video, we are going to show to solve a non linear equation using Matlab.
    Here we are going to consider four non-linear equations as examples.
    The first equation is a quadratic equation.
    The equation writes x square, minus five x, plus four, equals 0.
    It’s easy to obtain theoretical solutions of this equation.
    It’s considered here in order to compare theoretical and numerical Matlab solutions.
    The second equation considered here, is a cubic equation.
    It writes: x cubic minus, square root of 2 plus square root of 3 plus square root of 5, all times x square, plus,
    Square root of 6 plus square root of 10 plus square root of 15, a;; times x,
    minus square root of 30.
    Equals 0.
    Here again we have considered this equation because it is possible to obtain the solutions analytically.
    The third equation to be solved writes:
    Exponential of the square root of x, minus,
    X times logarithm of x the all square. Is equal to 0.
    For this equation, it is more laborious to obtain analytical solutions.
    The fourth, and last equation, involves trigonometric functions.
    It writes, 2 times cosine of x, plus 5 times sine of x, minus 3, equals 0.
    Here, it is possible to find the theoretical solutions,
    But deriving solutions needs few steps using some trigonometric rules.
    There are several ways to solve non-linear equations with Matlab, here we will use the function v ai p solve.
    The syntax of the function writes as follows:
    S is equal to v p ai solve, and three parameters, eqn, var and init param.
    S is the solution of the equation, as solved by the function v p ai solve.
    It is the output of the function.
    V p ai solve is the function name. It should be written in using lower case letters.
    Commonly the function uses three parameters, three inputs.
    The first input, is eqn, or the function’s expression.
    The second input is the name of the variable or the equation’s unknown.
    And the last or third input, is the initial value.
    This is the initial guess of the solution.
    Numerical solving highly depends on this initial guess.
    If the equation has multiple solutions, the function gives the solution which is the closest to the initial value.
    The third example is different from the two first equations.
    Here the equation is non-polynomial and involves exponential and logarithm functions.
    Thus, the function v p ai solve gives only one solution, even if the equation has multiple solutions.
    Here coding is quite similar.
    We have just changed the expression of the function f of x to match the new equation.
    And we have given the value of 10 to the initial value.
    We are going to add one line of coding.
    We are going to evaluate the function f in the obtained solution.
    The value of f here should be 0;
    Running the Matlab program gives one solution, which is approximately equal to 2.444, and the value of f in the solution is 0.
    Here again v p ai solve is working well;
    The last equation is also non-polynomial and involves trigonometric functions
    In terms of coding, we have just modified the expression of the function f of x.
    The solution will be here by default in radian.
    Thus we have add a fifth line in the code to convert the solution from radian to degrees.
    Running the code gives a solution around 0.21 radian or 12.05 degrees.

КОМЕНТАРІ •