How would I put this in a for loop ?

1 view (last 30 days)
noobmaster69
noobmaster69 on 22 Apr 2019
Commented: Image Analyst on 24 Oct 2019
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 Comment
Image Analyst
Image Analyst on 24 Oct 2019
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);

Sign in to comment.

Answers (1)

Andrei Bobrov
Andrei Bobrov on 22 Apr 2019
Edited: Andrei Bobrov on 22 Apr 2019
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!