problem with for and function inside other function
显示 更早的评论
hello, i do not handle very much with matlab so i'm asking for help...
i have this for...
for i=1:n1
t=0:0.001:Tp;
p=@(t)((t<=1).*(0)+((t>1)&(t<=1.4)).*(100*sin(2*pi()*(t-1)/T))+(t>1.4).*(0));
cos1=@(t)cos(2*pi()*i*(t)/Tp);
sin1=@(t)sin(2*pi()*i*(t)/Tp);
a0=(1/Tp)*quad(p,0,Tp);%constant
pp1=@(t)a0;
qa1=quad(p.*cos1,1,1.4);
a1(i)=(2/Tp)*qa1;
qb1=quad(p.*sin1,1,1.4);
b1(i)=(2/Tp)*qb1;
pp1=pp1+a1(i)*cos(2*pi()*i*t/Tp)+b1(i)*sin(2*pi()*i*t/Tp);
end
n1 and Tp are defined before the for. The error is with the qa1=quad(p.*cos1,1,1.4); i think i don't know how to multiply functions
also, i dont know if the last line "pp1=pp1+a1(i)*cos(2*pi()*i*t/Tp)+b1(i)*sin(2*pi()*i*t/Tp);" is corectly wrote
sorry for bad english, hope you can help me
采纳的回答
更多回答(1 个)
Youssef Khmou
2014-9-15
0 个投票
From your description , the error occurs when you calculate the integral of pxcos1 from 1 to 1.4, that is the quad function, you have to mention what the error says, is times Matrix dimensions must agree? if it is the case then you need adjust the length of p or cos1.
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!