Ongky Denny Wijaya
Ongky Denny Wijaya

Reputation: 297

Plotting Function Syms over [-2,7] in MATLAB

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?

Upvotes: 1

Views: 123

Answers (2)

If_You_Say_So
If_You_Say_So

Reputation: 1283

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

Upvotes: 1

Dominic D
Dominic D

Reputation: 1808

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]);

Upvotes: 3

Related Questions