contour+mesh+surf+max&min(14)

Mar 6th, 2022
163
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. f([-10 10],[-10 10],100,3);
2. function []=f(intervalpox,intervalpoy,korak, crtanje)
3.
4. x=linspace(intervalpox(1),intervalpox(2),korak);
5. y=linspace(intervalpoy(1),intervalpoy(2),korak);
6.
7. [X,Y] = meshgrid(x,y);
8. Z=sin(X.^2+Y.^2)./(X.^2+Y.^2);
9.
10. [Zmins, idx] = min(Z);
11. [~, Zjmin] = min(Zmins);
12. Zimin = idx(Zjmin);
13.
14. [Zmaxs, idx] = max(Z);
15. [~, Zjmax] = max(Zmaxs);
16. Zimax = idx(Zjmax);
17.
18. if(crtanje==1)
19.     mesh(X,Y,Z);
20. elseif(crtanje==2)
21.     surf(X,Y,Z);
22. elseif(crtanje==3)
23.     contour(X,Y,Z,20);
24. end
25.     hold on;grid on;
26.     plot3(X(Zimax,Zjmax),Y(Zimax,Zjmax),Z(Zimax,Zjmax),'ro');
27.     plot3(X(Zimin,Zjmin),Y(Zimin,Zjmin),Z(Zimin,Zjmin),'ro');
28.     xlabel('x');
29.     ylabel('y');
30.     zlabel('z');
31.     title('$z=\frac{\sin(x^2+y^2)}{x^2+y^2}$','Interpreter','latex')
32. end
33.