Solving a for loop

3 views (last 30 days)
Mangesh KAle
Mangesh KAle on 28 Oct 2019
Commented: Mangesh KAle on 28 Oct 2019
I need to us for loop for V1 V2 V3 equation used for solving membrane potential.
Can anyone please help me out.
%% Solving a Nerst Equation for Electrochemical Equilibrium
% Name-
% Date-23.10.2019
% Erev=(RT/zF)(log(Xout/Xin) %Nerst equation for electrochemical equilibrium
%% clean:
clc;
clear all;
close all;
%% parameters:
p.R=8.31; %Gas constant (J K^-1 mol^-1)
p.T=310 ;% Temperature (K)
p.F=96485; % Faraday Constant (C mol^-1)
Xout1=5; % output Ionic concentration for K+ ion
Xout2=145;% output Ionic concentration for Na+ ion
Xout3=110;% output Ionic concentration for Cl- ion
Xin1=140;% input Ionic concentration for K+ ion
Xin2=15;% input Ionic concentration for Na+ ion
Xin3=13;% input Ionic concentration for Cl- ion
z(1)=1;% Positive For K+ ion
z(2)=1;% Positive for Na+ ion
z(3)=-1;% Negative for Cl- ion
%% Calculation of Reverse potential:
X1 =[5 145 110]; % out ion concentration for K+ Na+ and Cl- in matrix form
X2 =[140 15 13];% input ion concentration for K+ Na+ and Cl- in matrix form
for i = 1:3
Erev(i) = (p.R*p.T)*(1/p.F) *(log(X1(:,i) /X2(:,i)))/(z(i)); % To calculate reversal potential
end
%% Calculation of Membrane potential:
min=-100;%minimum value of membrane potential
max=100;%maximum value of membrane potential
Vmem = [-100:100]; % Range of membrane potential
V1=Vmem-Erev(1); %Driving Force for K+
V2=Vmem-Erev(2);%Driving Force for Na+
V3=Vmem-Erev(3);%Driving Force for Cl-
%% Calculation of Resting Potential using Goldman equation:
p.Vt=27; % Vt=RT/F
% CASE:1
p.Pk=1; %relative permeability for K+
p.b1=0.03; %relative permeability for Na+
p.c1=0.1 ;%relative permeability for Cl-
%CASE:2
p.b2=1;
p.c2=1;
Erest(1)=p.Vt*log((p.Pk*Xout1 + p.b1*Xout2 +p.c1*Xin3)/(p.Pk*Xin1 +p.b1*Xin2 +p.c1*Xout3));
Erest(2)=p.Vt*log((p.Pk*Xout1 + p.b2*Xout2 +p.c2*Xin3)/(p.Pk*Xin1 +p.b2*Xin2 +p.c2*Xout3));
%% Illustration:
figure(1)
subplot(1,3,1)
plot(V1,Vmem)
xlabel('Driving Force(mV)')
ylabel('Membrane Potential(mV)')
grid on
title('Potassium ion')
subplot(1,3,2)
plot(V2,Vmem)
xlabel('Driving Force(mV)')
ylabel('Membrane Potential(mV)')
grid on
title('Sodium ion')
subplot(1,3,3)
plot(V3,Vmem)
xlabel('Driving Force(mV)')
ylabel('Membrane Potential(mV)')
grid on
title('Chlorine ion')
  4 Comments
darova
darova on 28 Oct 2019
You have Erev and Vmev
for i = 1:3
Erev(i) = (p.R*p.T)*(1/p.F) *(log(X1(:,i) /X2(:,i)))/(z(i)); % To calculate reversal potential
end
So what is the problem?
Mangesh KAle
Mangesh KAle on 28 Oct 2019
I need loop for V1 V2 and V3, and not for Erev

Sign in to comment.

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 28 Oct 2019
Edited: KALYAN ACHARJYA on 28 Oct 2019
I did not find the exact logic, as Vnem length 201 and Erev is 3
Is this?
for j=1:length(Vmem)
V1(j)=Vmem(j)-Erev(1); %Driving Force for K+
V2(j)=Vmem(j)-Erev(2);%Driving Force for Na+
V3(j)=Vmem(j)-Erev(3);%Driving Force for Cl-
end
The difference is, at initial you are subtractioning Erev respective number from all Vmen elements, here Invidual number Erev(j) from invidual Vmem elements.
Note: Without loop is recomended.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!