MATLAB Answers

Unsure what I did wrong

2 views (last 30 days)
justin pau
justin pau on 15 Feb 2020
Commented: David Hill on 16 Feb 2020
I want to plot a graph of y against x:
x=[0:2*pi]
y=exp(1)^x
plot(x,y)
But this error showed:
Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a power. Check that the matrix is
square and the power is a scalar. To perform elementwise matrix powers, use '.^'.

  0 Comments

Sign in to comment.

Accepted Answer

David Hill
David Hill on 15 Feb 2020
x=0:.01:2*pi;
y=exp(1).^x;
plot(x,y)

  2 Comments

justin pau
justin pau on 15 Feb 2020
what does the change mean? thanks
David Hill
David Hill on 15 Feb 2020
.^ needed for element-wise array operations
0:.01:2*pi splits up the interval into finer steps for plotting

Sign in to comment.

More Answers (1)

Steven Lord
Steven Lord on 15 Feb 2020
Don't try to raise exp(1) to the power of x. Just use exp on the array x directly.
x = 1:5;
y = exp(x);

  1 Comment

Sign in to comment.

Sign in to answer this question.

Tags