Integrate a function after having differenciated it

15 vues (au cours des 30 derniers jours)
Adrian Anton Alvarez
Adrian Anton Alvarez le 15 Déc 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);

Réponse acceptée

Walter Roberson
Walter Roberson le 16 Déc 2020
Modifié(e) : Walter Roberson le 16 Déc 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)

Plus de réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by