필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Why aren't my cases working correctly

조회 수: 1 (최근 30일)
Caprice Corlew
Caprice Corlew 2014년 10월 3일
마감: MATLAB Answer Bot 2021년 8월 20일
I made an if esleif else statement and a switch menu to plot the graphs but I cannot get the graphs to plot correctly. could someon hep me fix it? Its alot, sorry
switch answer case 1
period=1/frequency;
t=0:period*cycles:100;
y=amplitude*square(2*pi*frequency*t);
plot(t,y);
xlabel('Amplitude(v)')
ylabel('Time (s)')
title('Square wave')
case 2
period=1/frequency;
t=0:period*cycles:100;
y=amplitude*sin(2*pi*frequency*t);
plot(t,y);
xlabel('Time(s)');
ylabel('Amplitude');
title('Sine wave');
case 3
period=1/frequency;
t=0:period*cycles:100;
y=amplitude*cos(2*pi*frequency*t);
plot(t,y);
xlabel('Amplitude');
ylabel('Time (s)');
title('Cosine wave');
case 4
period=1/frequency;
t=0:period*cycles:100;
y=tan(pi*frequency*t);
ylim([-1.5*amplitude,1.5*amplitude]);
xlabel('Amplitude');
ylabel('Time (s)');
title('Tangent Curve');
case 5
t=0:.0001:5*tau;
dec= exp(-t/tau);
plot(t,tau);
xlabel('Amplitude (v)');
ylabel('Time (s)');
title ('Exponential Decay');
end
  댓글 수: 2
the cyclist
the cyclist 2014년 10월 3일
You say "I cannot get the graphs to plot correctly". What do you mean, specifically? Are you getting an error message? If so, what is the full content of that message. If not, then tell us in detail what is not correct.
Caprice Corlew
Caprice Corlew 2014년 10월 3일
I am not getting any error messages, but my graphs do not look how they should. For example, my exponential decay graph looks like a straight line, and my tangent graph just looks like a big block.

답변 (1개)

Matz Johansson Bergström
Matz Johansson Bergström 2014년 10월 3일
I would put period and t calculation outside of the switch and I think you want
t = linspace(0,period*cycles,100);
  댓글 수: 2
Caprice Corlew
Caprice Corlew 2014년 10월 3일
I tried that and they are still not plotting correctly.
Matz Johansson Bergström
Matz Johansson Bergström 2014년 10월 3일
편집: Matz Johansson Bergström 2014년 10월 3일
Ok, I only tried the sine wave and cosine wave. If you changed them you will get a correct answer for all cases but case 5 in which you use another mapping.
As for case 5 I have to assume that tau is a constant. In that case you want to have 'dec' as the amplitude. So case 5 becomes:
t = 0:.0001:5*tau;
dec = exp(t*tau);
plot(-t, dec);

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by