Plotting a graph with a confusing equation

1 Ansicht (letzte 30 Tage)
Millie Jones
Millie Jones am 24 Mär. 2020
Kommentiert: John D'Errico am 24 Mär. 2020
I am given the equation xxx+x*x+2x between -pi and pi, but when Matlab says I have to perform elementwise multiplication:
x = linspace(-pi,pi,100);
y= x.*x.*x+x.*x+2.*x;
plot(y)
However, the graphs for xxx+x*x+2x and x.*x.*x+x.*x+2.*x look different (xxx+x*x+2x is steeper), is there another way to do this?
For reference, here are the two graphs
y=xxx+x*x+2x:
y=x.*x.*x+x.*x+2.*x
Thanks.

Akzeptierte Antwort

John D'Errico
John D'Errico am 24 Mär. 2020
Bearbeitet: John D'Errico am 24 Mär. 2020
How to lie with statistics. ;-) (Yes, that is the name of a little book I read long ago.)
My point is, not that you or anyone is intentionally trying to lie here, but that by changing the axis scaling, it is easy to make one curve look completely unalike another, or to convince someone that something looks very different from what they might otherwise conclude.
Yes, you definitely need to use element-wise multiplication. But then you need to use plot correctly!
x = linspace(-pi,pi,100);
y = x.*x.*x+x.*x+2.*x;
% plot(y) % WRONG!!!!
plot(x,y) % correct
This looks as I would expect. However, now lets change the auto-scaling that MATLAB uses, into the apparent scaling used in your first plot.
axis([-9,9,-7,7])
grid on
Identically the same plot, but it certainly looks different. You were rushing to draw conclusions about something, based on nothing more significant than an axis scaling.
The point being to always beware of the axes on a plot, don't jump to conclusions.
As I said, this is a textbook case of how creative plotting can result in an interesting set of conclusions. Now, just imagine someone actually wanted to convince someone of anything they want? Again, it is amazingly easy to do. Just manipulate the plots to look as you want them to look. ;-) Sad, but true. And there are too many people in this world willing to do exactly that.
  2 Kommentare
Millie Jones
Millie Jones am 24 Mär. 2020
Haha! I'm not a lier, just clumsy! Thanks so much for your help, my graph now looks like the graph I inteneded it to be :)
John D'Errico
John D'Errico am 24 Mär. 2020
Oh, I know that you are not a liar. That part was never in question. :)
The point really is important though, especially in these days of disinformation. Do you see how easy it is to create a completely different impression of something, merely by how one decides to represent the information?
Anyway, I'm glad this fixed it for you.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by