Clear Filters
Clear Filters

How Can I Plot y=10*exp(-5*t)*t function?

7 views (last 30 days)
I wrote this code given in the below;
hold on;
and I give this error; Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise
multiplication, use '.*'.
How can i handle it.

Accepted Answer

Praveen Kumar Pakkirisamy
It is not a big problem and I will tell you what your problem is and then you can write the code yourself then.
Let me tell you how plot works in Matlab. For example If you want to plot for Y=t*exp(3*t), you will do the following.
t=0:1:10 %Now t has values [0 1 2 3 4 5 6 7 8 9 10] which is a row vector of the size (1 * 11)
y=t.*(exp(3*t)) % .* I have used this multiplication, because t is of size(1*11) and exp(3*t) is also (1*11)
So basically * means matrix multiplication in matlab and here it does (1*11) by (1*11) which is not possible. What you actually want is the first element of t to be multiplied by first element of exp(3*t) which is (0*0) and second element by second element and so on,This is called Element-wise-Multiplication.
t= 0 1 2 3 4 5 6 7 8 9 10
exp3*t= 0 0 0 0 0 0 0.0001 0.0026 0.0532 1.0686
Now if you multiply by using (.*) command, you will end up in (1*11) vector again which will be stored in y.
So you can plot now using plot command.
Whenever you errors like this,you can use size command. Here size(t) gives you the answer 1 11 which means 1 row and 11 column, Likewise if you enter size(exp(3*t)), again it will give you 1 11 and it will give you an intuitive sense why it is not multiplying.
  1 Comment
Furkan Fatih Durat
Furkan Fatih Durat on 9 Mar 2019
Thanks for your explanation. This information is so helpful for me

Sign in to comment.

More Answers (0)


Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!