How to correctly change a variable from a single number to an array.
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello, I oringinally wrote this matlab code to model the FitzHugh-Nagumo action potential. Now I'm trying to modify the model to get a string of action potentials. To do this I need to change all the state variables to array shown below:
These equations:
% Fitzhugh-Nagoma model parameters
e=0.03; k=3; a=0.05;
Are changed to this:
% Fitzhugh-Nagoma model parameters
e=[0.03 0.03]; k=[3 3]; a=[0.05 0.05];
However when I do this the code doesn't run. Can somebody explain what needs to change in the rest of the code to get it to work? Thanks a lot!
%Clear command window and workspace
clear
close all
clc
% Fitzhugh-Nagoma model parameters
e=[0.03 0.03]; k=[3 3]; a=[0.05 0.05];
i = 0.001;
figure(1);
hold on
u=zeros(100000,1);
v=zeros(100000,1);
t=zeros(100000,1);
% Initial conditions:
u(1)=0.6;
v(1)=0.0;
t(1)=0;
dt=0.001;
%==========================================================================
% Forvard Euler Method, for soluing the ODE
%==========================================================================
for i=1:1:500000
t(i+1)=t(i)+dt;
u(i+1) = u(i)+ dt*((1/e)*((k*u(i)*(u(i)-a)*(1-u(i)))-v(i)));
v(i+1) = v(i)+ dt*(u(i)-v(i));
end
% Getting the plot
figure(1);
plot(t,u)
legend('u','Trajectory')
title('Time Series Plot')
xlabel('Time')
ylabel('u')
xlim([0 5])
0 Commenti
Risposta accettata
Jan
il 24 Nov 2018
Modificato: Jan
il 24 Nov 2018
e = [0.03 0.035]; k = [3 3]; a = [0.05 0.05];
n = 500000;
u = zeros(n, 2);
v = zeros(n, 2);
t = zeros(n, 1);
% Initial conditions:
u(1, :) = 0.6;
v(1, :) = 0.0;
t(1) = 0;
dt = 0.00001;
% Forward Euler Method, for soluing the ODE
for i = 1:n - 1
t(i+1) = t(i) + dt;
u(i+1, :) = u(i, :) + dt * ((1 ./ e) .* ...
((k .* u(i, :) .* (u(i, :) - a) .* (1 - u(i, :))) - v(i, :)));
v(i+1, :) = v(i, :) + dt * (u(i, :) - v(i, :));
end
figure;
plot(t, u)
All you have to do is to define u and v as matrices instead of vectors and to change \ and * to the elementwise operations .\ and .* . Then acces the subvectors as u(i, :) instead of u(i).
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!