简体   繁体   中英

MATLAB: Symbolic Toolbox Plotting versus Discreet Plotting

I'm wondering if anyone has any insight into why these two plot commands produce domains that are orders of magnitude different?

syms t
x1Axis = 0:.01:10;
fun1(t) = sin(t)
plot(sin(x1Axis))
hold on
y = sin(x1Axis)
plot(x1Axis, y)

fun1(t) is plotted "symbolically" while y is evaluated and plotted "discreetly". Should I be using a different plot method in the case of the first function?

No, you are not plotting the symbolic function correctly.

In your code, the instruction plot(sin(x1Axis)) is not a symbolic plot, but a numeric plot of the sine versus the index of each value.

From the plot documentation page :

plot(Y) creates a 2-D line plot of the data in Y versus the index of each value.

  • If Y is a vector, then the x-axis scale ranges from 1 to length(Y) .

To plot the symbolic function use fplot .

The following example will allow you to see that both the symbolic and numeric plots are the same:

xmin = 0;
xmax = 10;

% Symbolic Plot.
syms t
fun1(t) = sin(t);
fplot(fun1, [xmin xmax], '-r');

hold on;

% Numeric Plot.
x = xmin:.01:xmax;
y = sin(x);
plot(x, y, '--g');

% Add legend.
legend('Symbolic Plot', 'Numeric Plot', 'Location', 'north');

This is the result:

正弦:符号和数字图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM