Plotting two functions that depend on boundary conditions.

1 次查看(过去 30 天)
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 中查找有关 Labels and Styling 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by