1
votes

I want to plot graph and point of data. I have tried to make MATLAB code as below.

clear;clc;
syms x;
f=-5/21*x^2+31/21*x+19/7;
xi=[6 -1 3];
yi=[3 1 5];
fig=ezplot(f);
set(fig,'color','r','linewidth',2);
hold on;
plot(xi,yi,'p','markersize',15,'markerfacecolor','y','markeredgecolor','b','linewidth',2,'markersize',10);
axis([min(xi)-1 max(xi)+1 min(yi)-1 max(yi)+1]);
grid on;

and the result as below. enter image description here

Why the graph of quadratic equation can't plotted over x in -2 into 7? How to fix it?

2

2 Answers

3
votes

The second argument to ezplot allows you to set the interval for the x-axis. You can do it like so:

syms x;
f=-5/21*x^2+31/21*x+19/7;
fig=ezplot(f, [-2,7]);

Matlab suggests you use fplot instead, which you can easily substitute.

syms x;
f=-5/21*x^2+31/21*x+19/7;
fig=fplot(f, [-2,7]);
1
votes

You could always use xlim(limits) as in xlim([-2 7]) on your plot after they're plotted too.