Issue with numerical integration of two variable function
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Bathala Teja
el 20 de Sept. de 2021
Comentada: Bathala Teja
el 22 de Sept. de 2021
I want to do integration of two variable function w.r.t one variable.
A = @(x, y)cos(x)+sin(y)
B = @(x, y)(A-integral(@(x)A, 0 , 2*pi))
How to see the output here??
0 comentarios
Respuesta aceptada
Walter Roberson
el 20 de Sept. de 2021
A = @(x, y) cos(x)+sin(y)
B = @(x, y) A(x,y)-integral(@(X)A(X,y), 0 , 2*pi, 'ArrayValued', true)
fsurf(B, [-pi pi -pi pi])
4 comentarios
Walter Roberson
el 22 de Sept. de 2021
It depends what you mean by "possible".
If you mean that you want to get the formula cos(x) + sin(y) - 2 * pi * sin(y) as your output, then that is certainly not something you could ever get through numeric methods, so it would require either using the Symbolic Toolbox or else doing equivalent processing such as text manipulation.
You know from examination that cos(x) + sin(y) is separable, so int(cos(x) + sin(y), x, 0, 2*pi) can be expanded into int(cos(x),x, 0, 2*pi) + int(sin(y), x, 0, 2 * pi) .
The second of those is constant in x, so the second of those is sin(y) * (2*pi) - sin(y) * (0) which is sin(y) * 2*pi
The first part, int(cos(x), x, 0, 2*pi) is (-sin(x) evaluated at 2*pi) - (-sin(x) evaluated at 0) which is -0 - (-0) which is 0.
So the entire integral is going to come out as sin(y) * 2*pi
You then subtract that from the original function cos(x) + sin(y) so you are going to get cos(x) + sin(y) - sin(y) * 2*pi
This approach requires a small knowledge of the integral of trig functions -- knowing how to integrate cos(x).
But this approach requires human knowledge of how to read the formula cos(x) + sin(y) and the formula involving the integral. The parts of MATLAB that are able to read a formula like that and have the knowledge of what it means and how to integrate... well, that's exactly what the Symbolic Toolbox does.
So as a human, you can find the solution fairly easily. Biut as a computer, you need the Symbolic Toolbox, or at least software that is programmed with enough calculus knowledge to handle all of the cases you need.
Más respuestas (2)
Sargondjani
el 20 de Sept. de 2021
Editada: Sargondjani
el 20 de Sept. de 2021
You created only function handles. So f(x,y) = .....
To compute the numerical value you need to assign numerical values to x and y. So for example:
y=0;
x=1;
B_value = B(x,y);
0 comentarios
Steven Lord
el 20 de Sept. de 2021
A = @(x, y)cos(x)+sin(y);
B = @(x, y)(A-integral(@(x)A, 0 , 2*pi));
Your expression for B won't work for two reasons. The integral function requires the function handle you pass into it as the first input to return a numeric array, but yours returns a function handle. Even if that worked, you would then try to subtract that result from a function handle and arithmetic on function handles is not supported.
From your description it sounds like you want B to be a function of one variable, but you need to pass two inputs into your A function handle. Assuming you want to fix the value of x and make B just a function of y, evaluate A inside your expression for B:
A = @(x, y)cos(x)+sin(y);
fixedX = 0.5;
B = @(y) A(fixedX, y)-integral(@(z)A(fixedX, z), 0 , 2*pi)
B(0.25)
Ver también
Categorías
Más información sobre Calculus 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!