make a butterfly effect graph in matlab

To create a butterfly effect graph, we first need to generate data from the Lorenz system, which is a set of differential equations that describes how the state of a certain physical system evolves over time. In the Lorenz system, small changes in the initial conditions of the system can lead to very different outcomes over time, which is the basis of the butterfly effect.

Here's some code that generates data from the Lorenz system and plots it as a butterfly effect graph using Matlab:

main.m
% Lorenz system parameters
sigma = 10;
beta = 8/3;
rho = 28;

% Time step and duration of simulation
dt = 0.01;
t = 0:dt:50;

% Initial conditions
x0 = [1 1 1];

% Function that computes the derivative of the state vector
f = @(t,x) [sigma*(x(2)-x(1));  ...
            x(1)*(rho-x(3))-x(2); ...
            x(1)*x(2)-beta*x(3)];

% Solve the Lorenz system using ode45
[t,x] = ode45(f, t, x0);

% Plot the x vs. z component of the state vector
plot(x(:,1), x(:,3))
xlabel('x')
ylabel('z')
title('Butterfly Effect in the Lorenz System')
536 chars
26 lines

The resulting plot should show a sideways figure-eight shape, which is characteristic of the butterfly effect in the Lorenz system. You can experiment with different initial conditions and parameters to see how they affect the shape of the graph.

gistlibby LogSnag