Question
Convert the following matlab code to C+ steps = 500; %This simulation runs for 500 steps count = 0; count1 = 0; newfunc = [];
Convert the following matlab code to C+
steps = 500; %This simulation runs for 500 steps
count = 0; count1 = 0;
newfunc = []; newfunc1 = [];
a=0.02; b=0.25; c=-65; d=6; V=-64; u=b*V; V1=-64; u1=b*V1; w=100; VV=[]; VV1=[]; uu=[]; uu1=[]; tau = 0.25; tspan = 0:tau:steps; %tau is the discretization time-step %tspan is the simulation interval T1=50; %T1 is the time at which the step input rises I = 0:0.25:20; for new = 1:length(I) for t=tspan V = V + tau*(0.04*V^2+5*V+140-u+I(new)); u = u + tau*a*(b*V-u); if V > 30 VV(end+1)=30; %VV is the time-series of membrane potentials V = c; u = u + d; if t > 200 count = count+1; end I_B = w*1; else VV(end+1)=V; I_B = w*0; end; V1 = V1 + tau*(0.04*V1^2+5*V1+140-u1+I_B); u1 = u1+tau*a*(b*V1-u1); if V1 > 30 VV1(end+1) = 30; V1 = c; u1 = u1 + d; if t > 200 count1 = count1+1; end else VV1(end+1) = V1; end uu(end+1)=u; uu1(end+1)=u1; end; newfunc(new)=count/300; newfunc1(new)=count1/300; count = 0; count1 = 0; VV = []; VV1 = []; end I_A = 1:length(I); figure(1) subplot(2,1,1) plot(I_A,newfunc,'r*-'); axis([0 max(I_A) 0 max(newfunc)])
subplot(2,1,2) plot(I_A,newfunc1,'b*-'); axis([0 max(I_A) 0 max(newfunc1)])
figure(2) plot(newfunc,newfunc1,'m*');
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started