In: Mechanical Engineering
Matlab
Create/write a function that takes an input of x and y data, and a string (either linear? or quadratic), sets up a linear system of equations (Ax = b), and solves and plots the model.
x = A\B
x = mldivide(A,B)
x = A\B solves the system of linear equations A*x = B. The matrices A and B must have the same number of rows. MATLAB displays a warning message if A is badly scaled or nearly singular, but performs the calculation regardless.
If A is a scalar, then A\B is equivalent to A.\B.
If A is a square n-by-n matrix and B is a matrix with n rows, then x = A\B is a solution to the equation A*x = B, if it exists.
If A is a rectangular m-by-n matrix with m ~= n, and B is a matrix with m rows, then A\B returns a least-squares solution to the system of equations A*x= B.
x = mldivide(A,B) is an alternative way to execute x = A\B, but is rarely used. It enables operator overloading for classes
A = magic(3); B = [15; 15; 15]; x = A\B
x = 3×1 1.0000 1.0000 1.0000