Tutorialspoint

Matlab Compatible Example

[x,y] = meshgrid(-2:.2:2);
g = x .* exp(-x.^2 - y.^2);
surf(x, y, g)
print -deps graph.eps

Matlab Curve fitting

x = [1 2 3 4 5 6]; y = [5.5 43.1 128 290.7 498.4 978.67];   %data
p = polyfit(x,y,4)   %get the polynomial

% Compute the values of the polyfit estimate over a finer range, 
% and plot the estimate over the real data values for comparison:
x2 = 1:.1:6;          
y2 = polyval(p,x2);
plot(x,y,'o',x2,y2)
grid on

Matlab Finding roots

p = [1 7 0  -5 9];
r = roots(p)

Matlab Polyvalm

p = [1 7 0  -5 9];
X = [1 2 -3 4; 2 -5 6 3; 3 1 0 2; 5 -7 3 8];
polyvalm(p, X)

Matlab Evaluating Polynomial

p = [1 7 0  -5 9];
polyval(p,4)

Matlab Solving System Equation

A = [5, 9; 3, -6];
b = [5;4];
A \ b

Matlab Solving Higher Order

v = [1, -7,  3, -5, 9];
s = roots(v);

% converting the roots to double type
disp('Numeric value of first root'), disp(double(s(1)));
disp('Numeric value of second root'), disp(double(s(2)));
disp('Numeric value of third root'), disp(double(s(3)));
disp('Numeric value of fourth root'), disp(double(s(4)));

Matlab Solving Quadratic Equation

s = roots([1, -7, 12]);

disp('The first root is: '), disp(s(1));
disp('The second root is: '), disp(s(2));

Matlab Algebraic Function

y = roots([1, -5])

Matlab Algebra

roots([1, -5])

1 2 3 4 5 6 7 ... 13 Next
Advertisements
Loading...