필터 지우기
필터 지우기

Undefined function or method 'int' for input arguments of type 'double'. Error in ==> @(Y,n,t)in​t(cos((n*p​i)*t).*Y,t​,0,2)

조회 수: 4 (최근 30일)
t=linspace(0,0.4,100);
f=0;
for n=0:1:5;
evalin(symengine,'assume(n,Type::Integer)');
t=[0,0,0.8,0.8,2,2];
Y=[0,1,1,-1,-1,1];
line(t,Y,'color','r','linewidth',2)
grid on;hold on;
a=@(Y,n,t)int(cos((n*pi)*t).*Y,t,0,2);
b=@(Y,n,t)int(Y.*sin((n*pi)*t),t,0,2);
f=f+a(Y,n,t)*cos((pi*n)*t)+b(Y,n,t)*sin((pi*n)*t);
plot(t,f,'k','linewidth',2)
end

답변 (2개)

Mikhail
Mikhail 2014년 8월 22일
편집: Mikhail 2014년 8월 22일
Typically this means that matlab doesn't know this function. Try to type "help int" in the command window. You can check this way if you have such function. May be you have to install additional packages for certain functions.

John D'Errico
John D'Errico 2014년 8월 22일
편집: John D'Errico 2014년 8월 22일
INT is a tool from the symbolic toolbox. It has no idea what you want it to do when you just pass it a list of numbers.
In fact, I have no idea either what you intend, given the vectors t and Y that you have used.
t=[0,0,0.8,0.8,2,2];
Y=[0,1,1,-1,-1,1];
Are you somehow hoping that MATLAB will be smart enough to recognize that this list of points corresponds to a polygon in the (t,Y) plane, and then do an integration over the polygon, or maybe around the perimeter? Computers don't read your mind.
Yes, I see that BEFORE you wrote those lines where you defined t and Y, you ALSO defined t using linspace. Again, COMPUTERS DON'T READ MINDS. MATLAB has no idea which version of t you want here, so it uses the LAST t that you defined, here inside the for loop.
Even if you use trapz (which IS a tool for numerical integration of a list of points) you need to consider what it is you are doing, and IF that makes mathematical sense. Sorry, but from what I have seen of the code above, it makes no sense at all. So, again, you need to think carefully about what you need, and then write careful code that represents your goal.
  댓글 수: 1
Nabhdeep Bansal
Nabhdeep Bansal 2014년 8월 23일
편집: Walter Roberson 2019년 3월 10일
Sir, I am new to MATLAB. I have rectified errors as much as I could. Still the curves in the output are incorrect. The problem to be solved is to construct a Fourier series graph for different harmonics for the given Y~t plot. Please help and oblige. :)
t=[0,0,0.8,0.8,2,2]';
Y=[0,1,1,-1,-1,1];
f=0;
for n=1:1:2
line(t,Y,'color','r','linewidth',2)
grid on;hold on;
A=0.5*trapz(t,Y);
P=Y.*(cos(n*pi*t))';
Q=Y.*(sin(n*pi*t))';
Ax=trapz(t,P);
Bx=trapz(t,Q);
f=f+(Ax*cos(pi*n*t)+Bx*sin(pi*n*t));
final=A+f;
plot(t,final,'linewidth',2)
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by