Integrate a function after having differenciated it
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Adrian Anton Alvarez
am 15 Dez. 2020
Kommentiert: Adrian Anton Alvarez
am 16 Dez. 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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 16 Dez. 2020
Bearbeitet: Walter Roberson
am 16 Dez. 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)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!