plot of y = 2.*(x.^4 - x.^2) isn't right

조회 수: 2 (최근 30일)
Anna
Anna 2022년 3월 27일
댓글: Anna 2022년 3월 27일
I set x = linspace(-10, 10); y = 2.*(x.^4 - x.^2); plot(x, y)
and the graph is not correct. what did I do wrong?
  댓글 수: 3
Mahmoud Ashraf
Mahmoud Ashraf 2022년 3월 27일
hi can you write you equation (handwritten)
DGM
DGM 2022년 3월 27일
Seems fine to me.
x = linspace(-10, 10);
y = 2.*(x.^4 - x.^2);
plot(x, y)
It might be that you're working in a figure that's already had hold on set, and the axis extents are such that the curve is not visible. If that's the case, either clear the figure (clf) or set the axis limits to something appropriate (use xlim() or ylim())

댓글을 달려면 로그인하십시오.

답변 (1개)

Dave B
Dave B 2022년 3월 27일
I'm pretty sure that's correct, were you expecting to see more of a w-like shape? You might have to zoom in a bit for that (and it helps to add some more points:
tiledlayout(1,2)
nexttile
x = linspace(-10, 10);
y = 2*(x.^4 - x.^2);
plot(x, y)
title('default limits')
nexttile
x = linspace(-10, 10, 1000);
y = 2*(x.^4 - x.^2);
plot(x, y)
ylim([-1 6])
title('more points, zoomed in')
  댓글 수: 1
Anna
Anna 2022년 3월 27일
Yes expecting a w shape. Thanks!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by