Search code examples
matlabdifferential-equations

Plotting parameterized solutions in matlab


I need to plot parameterized solutions for the following systems of equations using t values from 0 to 0.3 incremented by 0.001 each time:

x′  =  12.3 x  −  2.7 y

y′  =  5.7 x  −  3.7 y

This is what I have so far, but I'm pretty sure my parametric curves are wrong. I'd be expecting some exponential looking thing, not a lot of straight lines. What am I doing wrong?

A = [ 12.3, -2.7; 5.7, -3.7 ]; %initial matrix
[P D] = eig(A); %finding eigenvalues and eigenvectors
i = [1;4.3]; %initial conditions
H = inv(P)*i; %solving for c1 and c2

t = 0:0.001:0.3; 
c1 = 0.2580; %constant
c2 = 4.2761; %constant
B1 = [0.9346;0.3558]; %eigenvector
B2 = [0.1775;0.9841]; %eigenvector
a = 11.2721; %eigenvalue
b = -2.6721; %eigenvalue

x1 = c1*B1*exp(a*t) + c2*B1*exp(b.*t);
x2 = c1*B2*exp(a*t) + c2*B2*exp(b.*t);

plot(x1,x2);

Solution

  • Your problem was calculating x1 and x2. Since B1 and B2 are vectors, doing this:

    x1 = c1*B1*exp(a*t) + c2*B1*exp(b.*t);
    x2 = c1*B2*exp(a*t) + c2*B2*exp(b.*t);
    

    made x1 and x2 2 by 301 matrices.

    The correct result is simpler: x = c1*B1*exp(a*t) + c2*B2*exp(b*t);

    and plotting it gives:

    plot(x(1,:),x(2,:));