The symbolic code is not running

syms t x a p q r a1 a2 A pr
f(1)=x+p*x^2/2;g(1)=a*x+q*x^2/2;h(1)=1+r*x;
for i=1:5 %(Can I take i=0:5)
fa(i) = subs(f(i),x,t);ga(i) = subs(g(i),x,t);ha(i) = subs(h(i),x,t);
f(i+1) =f(i)+a1*int(int(int((diff(fa(i),t,3)+(fa(i)+ga(i))*diff(fa(i),t,2)+ a1*diff(fa(i),t,1)*(diff(fa(i),t,1)+diff(ga(i),t,1))),t,0,x)));
g(i+1) =g(i)+a1*int(int(int((diff(ga(i),t,3)+(fa(i)+ga(i))*diff(ga(i),t,2)+ a1*diff(ga(i),t,1)*(diff(fa(i),t,1)+diff(ga(i),t,1))),t,0,x)));
h(i+1) =h(i)+pr*a2*int(int((diff(ha(i),t,2)+(fa(i)+ga(i))*diff(ha(i),t,1)+ A*ha(i)*(diff(fa(i),t,1)+diff(ga(i),t,1))),t,0,x));
end
f=f(1)+f(2)+f(3)+f(4)+f(5);
disp(f(i+1))
figure(1)
fplot(x,f) %% (for FIG. a1=1;a2=2;A=1;pr=1;)

10 件のコメント

MINATI
MINATI 2019 年 11 月 5 日
Please anyone have a look
Thanks in advance
MINATI
MINATI 2019 年 11 月 8 日
Dear Walter
if you have time to follow, please
KSSV
KSSV 2019 年 11 月 8 日
編集済み: KSSV 2019 年 11 月 8 日
What do you mean by not running?
Walter Roberson
Walter Roberson 2019 年 11 月 8 日
The code is running for me, doing everything it is documented to do.
It is slow code, but that is to be expected when each step involves a triple integral of everything that has gone before. And remember that when you compute the same expression multiple times in an expression, it is faster to compute it once and store into a variable and use the variable See for example the way you compute diff(ga(i),t,1) multiple times and remember that diff(ga(i),t,2) involves first computing diff(ga(i),t,1)
%(Can I take i=0:5)
Yes, just remember to add 1 to i in every place that you use i as an index, as it is not possible to index anything at 0. So you would assign to fa(i+1) and to f(i+1+1) and so on.
MINATI
MINATI 2019 年 11 月 8 日
編集済み: MINATI 2019 年 11 月 8 日
Is there any way to speed it up
Walter Roberson
Walter Roberson 2019 年 11 月 8 日
Find the expressions that are computed multiple times, such as diff(ga(i),t,1) and store them in variables and use the variables. For example,
f(i+1) =f(i)+a1*int(int(int((diff(fa(i),t,3)+(fa(i)+ga(i))*diff(fa(i),t,2)+ a1*diff(fa(i),t,1)*(diff(fa(i),t,1)+diff(ga(i),t,1))),t,0,x)));
can be changed to
dfa = diff(fa(i),t,1)));
d2fa = diff(dfa,t,1);
d3fa = diff(d2fa,t,1);
dga = diff(ga(i),t,1);
f(i+1) =f(i)+a1*int(int(int((d3fa+(fa(i)+ga(i))*d2fa + a1*dfa*(dfa+dga)),t,0,x)));
This will be more efficient.
However, most of the time will still be spent doing the triple integrals.
Are you trying to do something like a lagrange interpolating polynomial?
MINATI
MINATI 2019 年 11 月 9 日
@Walter
Are you trying to do something like a lagrange interpolating polynomial?
No, its Adomian decomposition method to solve coupled ODEs.
it takes so much of time but MATHEMATICA did it quickly.
Walter Roberson
Walter Roberson 2019 年 11 月 10 日
I had to stop calculating on the 5th iteration, as it was using 80 gigabytes of memory.
Walter Roberson
Walter Roberson 2019 年 11 月 10 日
You have triple nested integrals, but you only have bounds for one of the levels, which leads you open to issues about ending up with whatever constant of integration that the routines decide to throw in. Wouldn't it be better to use definite integrals for all of the calculations? At the very least you should be indicating the variable of integration.
MINATI
MINATI 2019 年 11 月 10 日
ok
Thanks Walter
for your interest and time

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

回答 (0 件)

タグ

質問済み:

2019 年 11 月 4 日

コメント済み:

2019 年 11 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by