how do I write the program that draws the two-dimensional integral surface of the function in Matlab ?

 Respuesta aceptada

Ameer Hamza
Ameer Hamza el 8 de Mayo de 2020
Editada: Ameer Hamza el 8 de Mayo de 2020

1 voto

You can draw it using meshgrid and surf
[X, Y] = meshgrid(linspace(-3,3));
Z = exp(-X.^2-Y.^2);
surf(X,Y,Z)
shading interp

9 comentarios

Beyza Taka
Beyza Taka el 8 de Mayo de 2020
Thank You but I need the surface of the function's integral.
Ameer Hamza
Ameer Hamza el 8 de Mayo de 2020
But the limits on the integral are constant. They need to be variable to plot a surface. Can you show which limits of the integral are varying?
Beyza Taka
Beyza Taka el 8 de Mayo de 2020
limits given from 0 to 2
Ameer Hamza
Ameer Hamza el 8 de Mayo de 2020
Editada: Ameer Hamza el 8 de Mayo de 2020
I guess you want something like this
[X, Y] = meshgrid(linspace(0,2));
fun = @(X,Y) integral2(@(x,y) exp(-x.^2-y.^2), 0, X, 0, Y);
Z = arrayfun(fun, X, Y);
surf(X,Y,Z)
shading interp
Beyza Taka
Beyza Taka el 8 de Mayo de 2020
yes but gives error on Line 3.
Ameer Hamza
Ameer Hamza el 8 de Mayo de 2020
There was a typo. Try again.
Beyza Taka
Beyza Taka el 8 de Mayo de 2020
Thank you very much, it works.
Ameer Hamza
Ameer Hamza el 8 de Mayo de 2020
I am glad to be of help.
Ameer Hamza
Ameer Hamza el 8 de Mayo de 2020
FYI, this is a faster version of the previous code in the comment
syms x y X Y
fun = matlabFunction(int(int(z,x,0,X),y,0,Y), 'Var', {X, Y});
[Xg, Yg] = meshgrid(linspace(0,2));
Z = arrayfun(fun, Xg, Yg);
surf(Xg,Yg,Z)
shading interp

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 7 de Mayo de 2020

Comentada:

el 8 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by