summaryrefslogtreecommitdiff
path: root/27/CH6/EX6.5.2/Example_6_5_2.sce
blob: 1a5ca34d2336777bfaa087cf4cef19323fcca565 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
clear;
clear;
clc;
close;
set(gca(),"auto_clear","off")        //hold on

//Get x(dot) = y;    y(dot)=x-(x^3);

A1 = [0 1;1 0]        //Jacobian at (0,0)
t1=det(A1)

A2 = [0 1;-2 0]        //Jacobian at (1,0) and (-1,0).
t2=det(A2)
tau2=trace(A2)

disp("Since, t1=-1, thus (0,0) is a SAddle Point.");
disp("As t2=2 and tau2=0, thus (1,0) and (-1,0) are Centers.");


[x y]=meshgrid(-5:0.5:5,-5:0.5:5);
Nx=21;
Ny=21;


for i=1:21
    for j=1:21
        E(i,j) = ((1/2)*(y(i,j)^2)) -((1/2)*(x(i,j)^2)) + ((1/4)*(x(i,j)^4));
        //contour(x,y,E,3);
    end
end

l=-5:0.5:5;
k=-5:0.5:5;
plot3d(l,k,E);
figure
subplot(331)
contour2d(l,k,E,2);

subplot(335)
for x=-2:0.1:2
    V=((-1/2)*(x^2))+((1/4)*(x^4));
    plot2d(x,V,style=-2)
end
subplot(339)
function xd=linear652(t,x)
    xd(1)=x(2);
    xd(2)=x(1)-x(1)^3;
      //x(dot);   x(2) means y.
      //y(dot);   x(1) means x.; 
  endfunction
  bound=[-4,-4,4,4];        //Bounds of x-axis and y-axis as [xmin ymin xmax ymax], change them according to your needs.
  nrect=16;     //increase it to get more number of curves, i.e. more information will be available.
  set(gca(),"auto_clear","off")        //hold on
  x=linspace(bound(1),bound(3),nrect);
  y=linspace(bound(2),bound(4),nrect);
  x0=[];
 
 for i=1:35
     x0=[x(i);y(i)];
     t0=0;
     t=0:0.01:3000;
     xout=ode(x0,t0,t,linear652);
     plot2d(xout(1,:),xout(2,:));
 end
 xtitle('Phase Portrait','x-axis ( x )','y-axis ( y )')