Q:

Write a function that will receive x and y vectors representing data points. The function will create, in one Figure Window, a plot showing these data points as circles and also in the top

0

Write a function that will receive x and y vectors representing data points. The function will create, in one Figure Window, a plot showing these data points as circles and also in the top part a second-order polynomial that best fits these points and on the bottom a third-order polynomial. The top plot will have a line width of 3 and will be a gray color. The bottom plot will be blue, and have a line width of 2. For example, the Figure Window might look like this

Figure Subplot of second and third order polynomials with different line properties The axes are the defaults. Note that changing the line width also changes the size of the circles for the data points. You do not need to use a loop.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

fitLineWidth.m

function fitLineWidth(x,y)

% Plots data points with order 2 and 3 

% polynomials fit through them, with line 

% widths and color specified

% Format of call: fitLineWidth(x,y)

% Does not return any values

subplot(2,1,1)

coefs = polyfit(x,y,2);

curve = polyval(coefs,x);

plot(x,y,'o',x,curve,'LineWidth',3,'Color',[0.5 0.5 0.5])

title('Second order')

subplot(2,1,2)

coefs = polyfit(x,y,3);

curve = polyval(coefs,x);

plot(x,y,'o',x,curve,'LineWidth',2, 'Color', [0 0 1])

title('Third order')

end

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now