How would I put this in a for loop ?

1 次查看(过去 30 天)
clc; clear; close all;
T=1; % Period
w0 = 2*pi/T; % frequency
Vm = 1; % Voltage amplitude
syms t;
v1 = Vm*sin((4*pi*t)/T);
v2= 2*Vm*sin((4*pi*t)/T);
v = piecewise(-T<=t<=-T/2,v1,-T/2<=t<=0,v2,...
0<=t<=T/2,v1,T/2<=t<=T,v2,...
T<=t<=T+T/2,v1,T+T/2<=t<=2*T,v2,...
2*T<=t<=2*T+T/2,v1,2*T+T/2<=t<=3*T,v2);
  1 个评论
Image Analyst
Image Analyst 2019-10-24
Original question, in case dummy deletes this one too:
How would I put this in a for loop ?
clc; clear; close all;
T=1; % Period
w0 = 2*pi/T; % frequency
Vm = 1; % Voltage amplitude
syms t;
v1 = Vm*sin((4*pi*t)/T);
v2= 2*Vm*sin((4*pi*t)/T);
v = piecewise(-T<=t<=-T/2,v1,-T/2<=t<=0,v2,...
0<=t<=T/2,v1,T/2<=t<=T,v2,...
T<=t<=T+T/2,v1,T+T/2<=t<=2*T,v2,...
2*T<=t<=2*T+T/2,v1,2*T+T/2<=t<=3*T,v2);

请先登录,再进行评论。

回答(1 个)

Andrei Bobrov
Andrei Bobrov 2019-4-22
编辑:Andrei Bobrov 2019-4-22
T = 1; % Period
Vm = 1; % Voltage amplitude
v = {@(t)Vm*sin(4*pi*t/T);
@(t)2*Vm*sin(4*pi*t/T)};
ii = rem(discretize(rem(t,T),(-1:.5:1)')-1,2)+1;
U_out = arrayfun(@(x,y)v{x}(y),ii,t);

Community Treasure Hunt

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

Start Hunting!

Translated by