Plotting two functions that depend on boundary conditions.

조회 수: 3 (최근 30일)
SnukeN3
SnukeN3 2018년 11월 18일
댓글: madhan ravi 2018년 11월 18일
I have two functions,
V_lamp_off(t)=Vs+(Voff-Vs)*y and V_lamp_on(t)=Vth+(Von-Vth)*exp(z). I want to plot V_lamp_off when the value is between 1 and 4 and plot V_lamp_on when the value is between 4 and 1. The length of the plot is driven by t. I can plot the two functions individually but want to show the shark tooth wave form. I've tried an if/then sequence with no luck.
if V_lamp_off <= Voff
then a = V_lamp_off;
elseif V_lamp_off >= Von
then a = V_lamp_on;
elseif V_lamp_on <= Voff
then a =V_lamp_off;
end
plot (t,a)
Any help would be appreciated.

채택된 답변

madhan ravi
madhan ravi 2018년 11월 18일
편집: madhan ravi 2018년 11월 18일
"I want to plot V_lamp_off when the value is between 1 and 4 and plot "
Which value do you mean?
Instead of
if V_lamp_off <= Voff
then a = V_lamp_off;
elseif V_lamp_off >= Von
then a = V_lamp_on;
elseif V_lamp_on <= Voff
then a =V_lamp_off;
end
plot (t,a)
should be
a=ones(1,numel(t))
idx=(V_lamp_off <= Voff )
a(idx)=V_lamp_off(idx)
iddx=(V_lamp_off >= Von)
a(idx)=V_lamp_on(idx)
plot(t,a)

추가 답변 (3개)

SnukeN3
SnukeN3 2018년 11월 18일
clc, clear
%ECE 203-001 Team Project
format compact
% Part 2
Vs=6;
Von=4;
Voff=1;
t=0:0.001:40;
Rlamp=2.0E4;
R=2.32E5;
C=47E-6;
T=R*C;
x=-t/T;
y=exp(x);
V_lamp_off=Vs+(Voff-Vs)*y
% Part 3
Vth=Vs*(Rlamp/(R+Rlamp));
t0=R*C*log10((Voff-Vs)\(Von-Vs));
tc=t0+R*C*log10((Von-Vth)\(Voff-Vth));
z=-t/T;
V_lamp_on=Vth+(Von-Vth)*exp(z)
%Visualization
if V_lamp_off <= Voff
then a = V_lamp_off;
elseif V_lamp_off >= Von
then a = V_lamp_on;
elseif V_lamp_on <= Voff
then a =V_lamp_off;
end
plot (t,a)

SnukeN3
SnukeN3 2018년 11월 18일
Closer, I think. The output wave from should have a log rising edge and an exponential falling edge, kind of a cool repeating shark fin. I'm getting a matrix full of ones and nothing on the graph

SnukeN3
SnukeN3 2018년 11월 18일
Made a small change and I'm very close to the desired out put. I'll check my math. Thanks!
a=ones(size(t));
idx=(V_lamp_off <= Von )
a(idx)=V_lamp_off(idx )
idx=(V_lamp_on >= Von )
a(idx)=V_lamp_on(idx )
plot(t,a)

카테고리

Help CenterFile Exchange에서 Scripts에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by