How would I put this in a for loop ?

1 Ansicht (letzte 30 Tage)
noobmaster69
noobmaster69 am 22 Apr. 2019
Kommentiert: Image Analyst am 24 Okt. 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 Kommentar
Image Analyst
Image Analyst am 24 Okt. 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);

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Andrei Bobrov
Andrei Bobrov am 22 Apr. 2019
Bearbeitet: Andrei Bobrov am 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!

Translated by