How to write Malvar window/piecewise function?
显示 更早的评论
I want to plot

I can use the piecewise function to get v(x) but I cannot figure out how to combine it into w_j(t).
% Create array of a_j's
a = linspace(1, 4, 4);
% Create array of alpha_j's
alpha = linspace(1/4, 7/4, 4);
%Malvar window for each j
for j = 1:3
syms x
v = piecewise(x<=0, 0, 0<x<=1, (sin(pi*x/2))^2, x> 1, 1);
fplot(v)
syms t
w = piecewise(-sqrt(alpha(j)^2) + a(j)<=t<=sqrt(alpha(j)^2) + a(j), sin((pi/2)*v((t - a(j) + alpha(j))/(2*alpha(j)))), a(j) + alpha(j)<t<a(j+1) - alpha(j), 1, -sqrt(alpha(j+1)^2) + a(j+1)<=t<=sqrt(alpha(j+1)^2) + a(j+1), cos((pi/2)*v((t - a(j+1) + alpha(j+1))/(2*alpha(j)))), 0);
fplot(w)
end
I have tried using if-else statements and heaviside function instead of piecewise and they also did not work.
Thanks
回答(1 个)
Walter Roberson
2018-5-14
You define v as a symbol (with a scalar value), but you use v(expression) . That is trying to index into the scalar symbol. You should define
v(x) = piecewise(x<=0, 0, 0<x<=1, (sin(pi*x/2))^2, x> 1, 1);
Note by the way that the ability to use range expressions of the form A < t <= B is not documented, which means that it could go away without notice. You should be using A < t & t <= B
类别
在 帮助中心 和 File Exchange 中查找有关 Assumptions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!