Generating sinusoidal wave in MATLAB but I get STRAIGHT line instead??

7 ビュー (過去 30 日間)
Susan
Susan 2011 年 6 月 26 日
I am trying to learn about the signals and wave for awhile now, It worked at the beggining but when I added few lines I get now curved line, I know it meant to be easy but not sure whats wrong .. I am using possion distribution !
here is my code..
function S = trial(lambdaMax,lambda,T)
t = 0;
I = 0;
S = [];
u = rand;
t = t - log(u)/lambdaMax;
while t < T
u = rand;
if (u <= lambda(t)/lambdaMax)
I = I+1;
S(I) = t;
end
u = rand;
t = t - log(u)/lambdaMax;
end
this is the script to run it,,
lambdaMax=50;
T=1;
lambda =@(x) lambdaMax * sin(x);
S = trial(lambdaMax,lambda,T);
figure
hold on
plot(S,lambda(S),'*')
xlabel('t')
ylabel ('sin(x)')
  4 件のコメント
Jan
Jan 2011 年 6 月 26 日
Well, as far as I remember the sinus *is* a curved line.
Naturally the computations are correct in the sense that Matlab interpretes the shown code correctly. So if you expect a different result, most likely your expectations are wrong.
Please take the time to formulate a question and explain the difference between "curved line" and "sin wave" with any details.
Susan
Susan 2011 年 6 月 26 日
I mean just a straight line but just in different angle perhaps I should not use curved.. its actually straight line and the expected the usual sin curved waves

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

採用された回答

Jan
Jan 2011 年 6 月 26 日
If you call your function "trial" with T=2*pi you get a full period of a sinusidal curve. With T=1 you get just the first part, which looks almost straight, but it has a small curvature.
  1 件のコメント
Susan
Susan 2011 年 6 月 26 日
Yeah your right.. its working but wasn't clear to me coz it T was 1.. Thank you :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics and Optimization についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by