Effacer les filtres
Effacer les filtres

how to use the mathmatical constant "e" in conjunction with a vector.

8 vues (au cours des 30 derniers jours)
SonOfAFather
SonOfAFather le 29 Août 2012
I am trying to use the mathmatical constant "e" in conjunction with a vector and each time i rum my script i tells me that the " * " is wrong. I have narrowed it down by removign things one piece at a time and everything runs great until i add the e back into my script. i saw somewhere that you can use exp() to make it work but in conjunction with the rest of the function i am not getiing it to work.
  1 commentaire
SonOfAFather
SonOfAFather le 29 Août 2012
i really don't like assigning e = exp(1) but if that works thats's fine. I would like to get this function done in a oneliner. here is what i have so far.
clear;
clc;
close all;
% create vector of time values
t = 0.0 : 0.01 : 5.0;
% evaluate function at time points
e = exp(1);
f = 22*cos(15*pi*t)*e.^(-0.5*t);
% plot t vs f(t)
figure(1)
plot(t,f);
xlabel('t (sec)');
ylabel('f(t)');
Error using *
Inner matrix dimensions must agree.
Error in tesst (line 8)
f = 22*cos(15*pi*t)*e.^(-0.5*t);

Connectez-vous pour commenter.

Réponse acceptée

Matt Tearle
Matt Tearle le 29 Août 2012
Your problem isn't the e, it's that the two parts you're trying to multiply are both vectors, hence you need .* instead of *:
f = 22*cos(15*pi*t) .* e.^(-0.5*t);
% ---vector--- ---vector--
But, as Wayne King says, don't use e.^x, use exp(x):
f = 22*cos(15*pi*t) .* exp(-0.5*t);
  1 commentaire
SonOfAFather
SonOfAFather le 29 Août 2012
thank you thank you i was pulling my hair out over this

Connectez-vous pour commenter.

Plus de réponses (1)

Wayne King
Wayne King le 29 Août 2012
Modifié(e) : Wayne King le 29 Août 2012
You need to post some code so we can see where you encounter an error. You can certainly use exp() with vectors.
x = 1:0.001:10;
y = exp(x);
% or
z = exp(1)*ones(100,1);
Of course, you can always define a variable.
e = exp(1);
but I don't think you should need to do that.
Also, don't forget the "dot" notation if that is necessary.
x = 1:0.001:10;
y = exp(-x.^2);
plot(x,y)
  1 commentaire
SonOfAFather
SonOfAFather le 29 Août 2012
thank you thank you i was pulling my hair out over this

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by