Undefined function or method 'int' for input arguments of type 'double'. Error in ==> @(Y,n,t)int(cos((n*pi)*t).*Y,t,0,2)
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (2)
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.
0 commentaires
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
le 23 Août 2014
Modifié(e) : Walter Roberson
le 10 Mar 2019
Voir également
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!