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)

3 vues (au cours des 30 derniers jours)
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

Réponses (2)

Mikhail
Mikhail le 22 Août 2014
Modifié(e) : Mikhail le 22 Août 2014
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 le 22 Août 2014
Modifié(e) : John D'Errico le 22 Août 2014
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 commentaire
Nabhdeep Bansal
Nabhdeep Bansal le 23 Août 2014
Modifié(e) : Walter Roberson le 10 Mar 2019
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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by