Not enough input arguments in trapz
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
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)
Respuesta aceptada
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.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!