MatLab plotting and curve fitting assignment

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/5

encourage image

There are no tags or description

Looks like no tags are added yet.

6 Terms

1
New cards

command for generating fine x grid in order to get smooth curves?

x_fit= 0: 0.1: 4;

2
New cards

command for fitting polynomials

p1 = polyfit(x, y, 1); % Linear (1st order)

p2 = polyfit(x, y, 2); % Quadratic (2nd order)

p4 = polyfit(x, y, 4); % 4th order

p5 = pol

3
New cards

command for evaluating polynomials on x_fit

y1 = polyval(p1, x_fit);

y2 = polyval(p2, x_fit);

y4 = polyval(p4, x_fit);

y5 = polyval(p5, x_fit);

4
New cards

command for plotting

figure;

plot(x, y, 'ko', 'MarkerFaceColor', 'k', 'MarkerSize', 8); % Original Data

hold on;

plot(x_fit, y1, 'r--', 'LineWidth', 1.5); % Linear

plot(x_fit, y2, 'b-.', 'LineWidth', 1.5); % Quadratic

plot(x_fit, y4, 'g-', 'LineWidth', 1.5); % 4th Order

plot(x_fit, y5, 'm-', 'LineWidth', 1.5); % 5th Order

hold off;

5
New cards

command for graph details

grid on;

title('Polynomial Curve Fitting');

xlabel('x');

ylabel('y');

legend('Data Points', 'Linear (1st)', 'Quadratic (2nd)', '4th Order', '5th Order',

'Location', 'southeast’);

6
New cards

command for displaying coefficient in the command window

disp('5th Order Polynomial Coefficients (Best Fit):');

disp(p5);