Sunteți pe pagina 1din 3

Bernadette Nguy

Guangfei Duan
MAE 376-02
06 September 2019

Homework 1

Problem 1)

Surf 0.4
[x,y] = meshgrid(-2:2,-2:3);
0.3
z = x.*exp(-x.^2-y.^2);
0.2
surf(x,y,z);
0.1

-0.1

-0.2

-0.3

-0.4
3
2 2
1 1
0 0
-1 -1
-2 -2

Contour
[x,y] = meshgrid(-2:2,-2:3); 0.3 0.30099
z = x.*exp(-x.^2-y.^2);
contour3(x,y,z,10,'ShowText','on'); 0.2
0.16722
0.10033
0.23411
0.16722
0.0334440.10033
0.1 0.033444

0 0.10033

-0.033444 0.033444
-0.1 0.033444
-0.033444-0.10033 -0.033444
-0.2
-0.10033
-0.16722
-0.3 -0.10033 -0.033444
-0.16722
3 -0.23411
-0.30099
2 2
1 1
0 0
-1 -1
-2 -2
Plot3
x=-2:.005:2; 0.4

y=-2:.005:2; 0.3
z=x.*exp(-x.^2-y.^2);
0.2
plot3(x,y,z);
0.1

-0.1

-0.2

-0.3

-0.4
2

1 2

0 1
0
-1
-1
-2 -2

Surf is a 3-D colored surface. Surf(X,Y,Z) uses C = Z, so color is proportional to surface height.
Contour is a contour plot. Contour(X,Y,Z) draws a contour plot of Z using vertices from the
mesh defined by X and Y. X and Y can be vectors or matrices. Plot3 plots lines and points in 3-D
space. Plot3(x,y,z), where x, y and z are three vectors of the same length, plots a line in 3-space
through the points whose coordinates are the elements of x, y and z.

Problem 2)
function F = non_linear(x)
F(1) = 3 * x(1) * (1 - x(1)) - x(1) * x(2) - (1 - exp(5*x(1)) ) ;
F(2) = x(2) - 3 * x(1) * x(2) ;
End

>> x0=[-5 5];fsolve(@non_linear,x0)

ans =

0.3333 -0.2875
Problem 3)
function [] = ODE ()
global mu;
Ic=[1;0]; %Initial conditions (@ t=0)
tspan=[0 6]; %Simulation time
[t,y]=ode45(@ODE,tspan,Ic); %Function call
plot(t,y(:,2),'-b');
xlabel('time','fontsize',16);
ylabel('x(t)','fontsize',16);
function dx=ODE(t,x)
mu=1;
dx=zeros(2,1);
dx(1)=x(2);
dx(2)=mu*(1-(x(1))^2)*x(2)-x(1);
end
end

S-ar putea să vă placă și