Integrate a function after having differenciated it
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Adrian Anton Alvarez
el 15 de Dic. de 2020
Comentada: Adrian Anton Alvarez
el 16 de Dic. de 2020
I would like to differenciate a function (2 variables) and after that integrate it, but its giving me errors all the time. You can see here an extract of the code. Does anybody now how can I do this?
u = @(x,y) sqrt(1-x).*y;
duxx = @(x,y) diff(u(x,y),x,2);
k = (1/2)*integral2(duxx,0,1,0,1);
0 comentarios
Respuesta aceptada
Walter Roberson
el 16 de Dic. de 2020
Editada: Walter Roberson
el 16 de Dic. de 2020
integral2 is a numeric integration routine. It will pass the function handle two arrays of values, and must return something the same size.
With your function handle, u(x, y) will be invoked, passing in the arrays. Your u is vectorized so it will return a numeric array.
The numeric array will then be passed as the first parameter to diff(), and the numeric x will be passed as the second parameter, and 2 will be passed as the third.
https://www.mathworks.com/help/matlab/ref/diff.html shows that three parameters are possible for diff() but only when the second is a positive integer representing the difference number and the third is the dimension number. The array of x values is not a dimension number.
You have gotten confused between the numeric diff() function and the symbolic diff() function which is calculus. The calculus diff does not work on function handles, just symbolic expressions and symbolic functions.
sym x y
duxx = matlabFunction(diff(u(x,y), x, 2), 'vars', [x, y])
integral2(duxx, etc)
Más respuestas (0)
Ver también
Categorías
Más información sobre Symbolic Math Toolbox 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!