Need advise: Is my implementation good ?

Hi, is my MATLAB code (please look below in my EDIT) good for solving this problem?
________________________________________________________________________________
This was the original question:
Hello, I have a question concerning differentiation and integration of multivariate functions. I am tryling to implement this in MATLAB:
1) We have a function in two variables, for example f(x,y):= x^2 exp( -(x-y)^2 )
2) First I want to differentiate it several times wrt to the second variable, lets say g(x,y) := (d/dy)^5 f(x,y)
3) Afterwards I fix y and integrate wrt to x. For example integrate g(x,0) over (-\infty,\infty)
My approach was to calculate the function g by hand and do the integration wrt to x with quadgk. Due to the fact that I need many different orders of derivatives this is really ineffective ... Can anyone please help me out ? Thanks !!
______________________________________________________________________
EDIT: The way I think it should work. MATLAB-Code:
syms x y;
fun = x.^2 exp( -(x-y).^2 );
for j=0:10;
FUNC = inline(diff(fun,y,j));
L = @(x) FUNC(x,0);
quadgk(L, -inf, inf,'RelTol',1e-8,'AbsTol',1e-12)
end;
Is this a good way? Any opinions of advanced MATLAB users ? Thanks

Respuestas (1)

Alan Weiss
Alan Weiss el 23 de En. de 2014

0 votos

Do you have Symbolic Math Toolbox?
If not, are you supposed to differentiate and integrate numerically or symbolically?
Alan Weiss
MATLAB mathematical toolbox documentation

1 comentario

Oscar
Oscar el 23 de En. de 2014
Editada: Oscar el 24 de En. de 2014
Hello,
I have MATLAB 7.8.0 ... I only used symbolic differentiation in this way A=inline(diff(f,z,4)). Due to the fact that I bought a MATLAB version from my university, I think that it is only a standard student edition.
In my case, the derivative of the function is not hard to calculate by hand. The function f(x,y):= x^2 exp( -(x-y)^2 ) serves as a good example. The case that I am working has a similar structure, but it is not possible to find a recursion formula for the derivatives. So lets stick to the function f as defined above.
I have to integrate the y-derivatives (of order 1 to N ) evaluated at y=0 over the whole real line. That is why I thougt it would be better to do symbolic differentiation at first. I want to proceed like this:
1) We put: f = @(x,y) x.^2 exp( -(x-y).^2 )
2) We put: g_k(x,y) := (d/dy)^k f(x,y)
3) We define the integrad like this: INTk = @(x) g_k(x,0)
4) We do the integration: quadgk(INTk, -inf, inf,'AbsTol',1e-12)
This is all really informal and I just can't get a working code ... Is the idea ok, or would you do it differently? Due to the fact that I have very little experience in using MATLAB I would be very thankful, if anyone could help me to implement this procedure.
With best regards, Oscar

La pregunta está cerrada.

Preguntada:

el 23 de En. de 2014

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by