Plotting two functions that depend on boundary conditions.

2 views (last 30 days)
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.

Accepted Answer

madhan ravi
madhan ravi on 18 Nov 2018
Edited: madhan ravi on 18 Nov 2018
"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)

More Answers (3)

SnukeN3
SnukeN3 on 18 Nov 2018
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 on 18 Nov 2018
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 on 18 Nov 2018
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)

Categories

Find more on Scripts in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!