Question:
v = [0.0476;0.7940;0.0738;-0.0083] u = [1 ,x, x.^2 ,x.^3] how to plot y= 0.0476 + 0.7940x +0.0738x.^2-0.0083x.^3 by u and v
Answer:
As the vector v is an array of coefficients from in ascending power of x; so first of all create a array (row matrix) of coefficients in decending order. In MATLAB, a row matrix of numbers acts as the coefficients of a polynominal, so as in our case:
v = [-0.0083 0.0738 0.7940 0.0476];
Have a look to this polynomial using the buil-in command given below:
v_poly = poly2sym(v)
Now there are two methods to plot this polynomial, one is by using fplot
command in which you need not to define the values of the variable in which the polynomial is defined.
fplot(v_poly); hold on;
Alternatively you can simply define the values of x using built-in command linspace and then plot the polynomial:
x = linspace(-5,5);
plot(x, polyval(v, x),'r.');
OUTPUT
v_poly = - (83*x^3)/10000 + (369*x^2)/5000 + (397*x)/500 + 119/2500
0 Comments