How Can I Plot y=10*exp(-5*t)*t function?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Furkan Fatih Durat
el 9 de Mzo. de 2019
Comentada: Furkan Fatih Durat
el 9 de Mzo. de 2019
I wrote this code given in the below;
t=0:0.01:1;
y=10*t*exp((-5)*t);
x=exp((-5)*t)*((-5)*t+1);
plot(t,y,'k');
hold on;
plot(t,x,'r');
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.
0 comentarios
Respuesta aceptada
Praveen Kumar Pakkirisamy
el 9 de Mzo. de 2019
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.
plot(t,y)
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!