フィルターのクリア

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

8 ビュー (過去 30 日間)
SonOfAFather
SonOfAFather 2012 年 8 月 29 日
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 件のコメント
SonOfAFather
SonOfAFather 2012 年 8 月 29 日
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);

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

採用された回答

Matt Tearle
Matt Tearle 2012 年 8 月 29 日
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 件のコメント
SonOfAFather
SonOfAFather 2012 年 8 月 29 日
thank you thank you i was pulling my hair out over this

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

その他の回答 (1 件)

Wayne King
Wayne King 2012 年 8 月 29 日
編集済み: Wayne King 2012 年 8 月 29 日
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 件のコメント
SonOfAFather
SonOfAFather 2012 年 8 月 29 日
thank you thank you i was pulling my hair out over this

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

カテゴリ

Help Center および File ExchangeGrid Lines, Tick Values, and Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by