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)

1 次查看(过去 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