Following are few of the Matlab interpreter commands to understand the geometries of some selected functions. These help me understand few of the complex convex optimization problems.
S.No. | Topic | Command | Description | Output |
1 | Norms | norm([3,4],1) | 7 | 7 |
norm([3,4],inf) | 4 | 4 | ||
norm([3,4],2) = norm([3,4]) | 5 | 5 | ||
2 | 2D plots | x=[-10:1:10]; plot(x, x.^2); | y = x^2 | |
x=[-10:1:10]; plot(x, 3.^x); | y = 3^x | |||
x=[-10:1:10]; plot(x, x.^3); | y = x^3 | |||
3 | 3D plots | t=[0:pi/30:6*pi]; x=t.*cos(t); y=t.*sin(t); z=t; plot3(x,y,z); grid on | x=t x cos(t) y=t x sin(t) z=t | |
[x,y]=meshgrid(-2:1:2,-2:1:2); surf(x,y,x.^2-y.^2) | z =x2−y2 | |||
[x,y]=meshgrid(-2:1:2,-2:1:2); surf(x,y,x.^2+y.^2) | z =x2+y2 | |||
[x,y]=meshgrid(-2:0.1:2,-2:0.1:2); surf(x,y,x.^2-y.^2) | z =x2−y2 | |||
[x,y]=meshgrid(-2:0.1:2,-2:0.1:2); surf(x,y,x.^2+y.^2) | z =x2+y2 | |||
[x,y]=meshgrid(-2:0.1:2,-2:0.1:2); surfc(x,y,x.^2+y.^2) | z =x2+y2 | |||
4 | Comparing graphs | [x,y]=meshgrid(-1:.1:1,-1:.1:1); subplot(1,2,1) surf(x,y,x.^2+y.^2) axis square subplot(1,2,2) contourf(x,y,x.^2+y.^2) axis square | z =x2+y2 | |
[x,y]=meshgrid(-1:.1:1,-1:.1:1); subplot(1,2,1) surf(x,y,sqrt(x.^2+y.^2) ) axis square subplot(1,2,2) contourf(x,y, sqrt(x.^2+y.^2) ) axis square | ||||
[x,y]=meshgrid(-1:.1:1,-1:.1:1); subplot(1,2,1) surf(x,y,nthroot(x.^4+y.^4, 4)) axis square subplot(1,2,2) contourf(x,y,nthroot(x.^4+y.^4, 4)) |
References:
- http://www.cs.helsinki.fi/group/joko/matlab.pdf
- http://www2.ohlone.edu/people2/bbradshaw/matlab/plotting2d.html
- http://web.mit.edu/10.001/Web/Course_Notes/matlab.pdf
No comments:
Post a Comment