syms variable also a variable of loop

Hi all,
I am using t as syms variable and also as the variable inside loop.I am not sure whether they are connected in the code below. They need to represent the same. Is there a way I can get rid of syms and keep integration part (y2) also inside the loop? Your suggestion will be highly appreciated.
Thanks
Dharma
.....................................................................................................................................
a=0.0799;
b=5.85;
N=2000;
dt=0.05;
%
syms x t
c2(x) = (dirac(x-1) + dirac(x-3)+dirac(x-5)+dirac(x-7)+dirac(x-9)+dirac(x-11))*4;
inner2 = c2(x)* exp(-10*(t-x));
y2 = matlabFunction(simplify(int(inner2, x, 0, t)));
%
t=zeros(N,1);
K=zeros(N,1);
t(1)=0;
K(1)=20;
for i=1:N
for j=1:N
t(i+1)=t(i)+dt;
K(i+1)=K(i)-a*dt*K(i)-b*dt*t(i)*y2(t(i))*K(i);
end
end

5 件のコメント

KSSV
KSSV 2022 年 4 月 12 日
Code looks fine. But why you want two loops here?
for i=1:N
for j=1:N
t(i+1)=t(i)+dt;
K(i+1)=K(i)-a*dt*K(i)-b*dt*t(i)*y2(t(i))*K(i);
end
end
Wont a single loop work?
Dharma Khatiwada
Dharma Khatiwada 2022 年 4 月 12 日
Thanks!
I was trying to make just one loop. Please ignore the another loop. But, I am trying to run integration part (pasted below) also inside loop so that there can be just one loop of t.
syms x t
c2(x) = (dirac(x-1) + dirac(x-3)+dirac(x-5)+dirac(x-7)+dirac(x-9)+dirac(x-11))*4;
inner2 = c2(x)* exp(-10*(t-x));
y2 = matlabFunction(simplify(int(inner2, x, 0, t)));
Is is feasible? Also, can I just get rid of syms x,t?
KSSV
KSSV 2022 年 4 月 12 日
You can substittue the values of x and t in y2.
Dharma Khatiwada
Dharma Khatiwada 2022 年 4 月 12 日
Could you please give the detail of such steps?
Thanks
KSSV
KSSV 2022 年 4 月 12 日
Already you are doing it right?
y2(t(i))

サインインしてコメントする。

回答 (1 件)

Dharma Khatiwada
Dharma Khatiwada 2022 年 4 月 12 日

0 投票

It is working right but it takes longer time to run. I am trying to see if the integration can also be kept inside to see relatively shorter runtime.
Please let me know.

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2022 年 4 月 11 日

回答済み:

2022 年 4 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by