How would I put this in a for loop ?

1 回表示 (過去 30 日間)
noobmaster69
noobmaster69 2019 年 4 月 22 日
コメント済み: Image Analyst 2019 年 10 月 24 日
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