Effacer les filtres
Effacer les filtres

Not enough input arguments in trapz

2 vues (au cours des 30 derniers jours)
Andrei
Andrei le 2 Juil 2023
I am currently trying to perfor, numerical integration inb polar coordinates. I used trapz function this way:
Nx = 402;
x = linspace(-L/2,L/2, Nx);
y = linspace(-L/2, L/2, Ny);
[X,Y] = meshgrid(x(2:end-1), y(2:end-1));
[TH,R] = cart2pol(X,Y);
alpha_1 = linspace(0, pi/5, Nx-2);
ro = linspace(0, 20, Nx-2);
P_1 = trapz(alpha_1, (trapz(ro, (abs(v).*R), 2)),1);
v is a complex valued (400,400) matrix with non zero elements. I wanted to find volume under this function within angle pi/5 (special region in my task). But I came across an error: Not enough input arguments in line with trapz(). Where is the mistale, I checked documentation, everything should be fine. I tried to remove dim = 1 in outer integral - got same error.
  1 commentaire
Catalytic
Catalytic le 2 Juil 2023
Modifié(e) : Catalytic le 2 Juil 2023
Please provide code that can demonstrate the error and then run it for us like I've done below. As you can see, when I run your code with fabricated values, I get a value for P_1 with no error messages.
Nx = 402;Ny=402; v=rand(400); L=100;
x = linspace(-L/2,L/2, Nx);
y = linspace(-L/2, L/2, Ny);
[X,Y] = meshgrid(x(2:end-1), y(2:end-1));
[TH,R] = cart2pol(X,Y);
alpha_1 = linspace(0, pi/5, Nx-2);
ro = linspace(0, 20, Nx-2);
P_1 = trapz(alpha_1, (trapz(ro, (abs(v).*R), 2)),1)
P_1 = 239.0549

Connectez-vous pour commenter.

Réponse acceptée

John D'Errico
John D'Errico le 2 Juil 2023
I would strongly suggest you should not name your own functions the same as existing code. If you do, then this is exactly the type of error you should expect. To learn if what I suspect is true, do this at the command line.
which trapz -all
It should show a function named trapz that you wrote. If so, then rename your function.

Plus de réponses (0)

Catégories

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

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by