Borrar filtros
Borrar filtros

Not enough input arguments in trapz

2 visualizaciones (últimos 30 días)
Andrei
Andrei el 2 de Jul. de 2023
Respondida: John D'Errico el 2 de Jul. de 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 comentario
Catalytic
Catalytic el 2 de Jul. de 2023
Editada: Catalytic el 2 de Jul. de 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

Iniciar sesión para comentar.

Respuesta aceptada

John D'Errico
John D'Errico el 2 de Jul. de 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.

Más respuestas (0)

Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by