Help me about plot and linspace in matlab ?

for example I plot the graph y = 2/x by plot command :
x = linspace(1,10,100);
y = 2./x;
plot(x,y,'linewidth',4,'color','r')
It run normally and doesn't have error. But now I plot the graph y = (2/x)^3 by plot:
x = linspace(1,10,100);
y = (2./x)^3;
plot(x,y,'linewidth',4,'color','r')
It appear the error : ??? Error using ==> mpower Inputs must be a scalar and a square matrix. Help me fix it. I think I put the dot wrong. thanks very much.

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 12 月 25 日

0 投票

It should be
x = linspace(1,10,100);
y = (2./x).^3;
plot(x,y,'linewidth',4,'color','r')

3 件のコメント

Nguyen Trong Nhan
Nguyen Trong Nhan 2013 年 12 月 25 日
Why I have to that without y = (2./x)^3 .
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 12 月 25 日
If x=[1 2 3] , x^3 is not possible, what you need is x.^3, operation element by element
Nguyen Trong Nhan
Nguyen Trong Nhan 2013 年 12 月 25 日
Ok, I see. thanks you very much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by