How do i store value in a array from for loop?

1 view (last 30 days)
p=0;
q=0;
G=0.1;
K=0.2;
M=1.2;
c=20;
Ms=0.8;
eps_v=0;
eps_s=0;
deps_v= 0.0001;
deps_s= .67*deps_v;
for i=1:5
dp= K*deps_v;
dq= (3*G)*deps_s;
pt=p+dp;
qt=q+dq;
f= qt-M*pt+c;
if (f<0)
deps_ve=deps_v;
deps_se=deps_s;
deps_vp=0;
deps_sp=0;
else
dpe=M*p-c-q/(.67-M);
dqe=0.67*dpe;
deps_ve=dpe/K;
deps_se=dqe/(3*G);
deps_vp=deps_v-deps_ve;
deps_sp=deps_s-deps_se;
dpp= ((K-((0.67*K*K*M-K*K*M*Ms)/(0.67*M*K-K*M*Ms+3*G)))*deps_vp)+ (((2*G*K-3*K*G*Ms)/(0.67*M*K-K*M*Ms+3*G))*deps_sp);
dqp= (((3*M*G*K)/(0.67*M*K-K*M*Ms+3*G))*deps_vp)+(((3*G)-((9*G*G)/(0.67*M*K-K*M*Ms+3*G)))*deps_sp);
dp= dpe+dpp;
dq= dqe+dqp;
end
p=p+dp;
q=q+dq;
eps_v=eps_v+deps_ve+deps_vp;
eps_s=eps_s+deps_se+deps_sp;
end
disp(p)
disp(q)
disp(eps_v)
disp(eps_s)
here i want to store the updated values of p and q in a array so that i can plot p,q
please tell me how to do it

Accepted Answer

darova
darova on 29 Mar 2020
I give you simple example for a start
n = 10;
y = zeros(1,n);
for i = 1:n-1
x = x + dx;
dy = sin(x);
y(i+1) = y(i) + dy;
end

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!