How would I put this in a for loop ?

1 vue (au cours des 30 derniers jours)
noobmaster69
noobmaster69 le 22 Avr 2019
Commenté : Image Analyst le 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 commentaire
Image Analyst
Image Analyst le 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);

Connectez-vous pour commenter.

Réponses (1)

Andrei Bobrov
Andrei Bobrov le 22 Avr 2019
Modifié(e) : Andrei Bobrov le 22 Avr 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