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!