MATLAB Answers

0

'for loop' summation containing symbolic variable

Asked by Aniket Masaye on 18 Jan 2019
Latest activity Commented on by Aniket Masaye on 18 Jan 2019
I tried to carry out a summation in 'for loop' which has symbolic variable in it. but it is showing some errors. I am attaching my script file. Please tell me where I am getting wrong.

  0 Comments

Sign in to comment.

2 Answers

Answer by Stephan
on 18 Jan 2019
Edited by Stephan
on 18 Jan 2019
 Accepted Answer

Hi,
some bugs - try:
clear
syms n
Cs=1000;
k=1e8;
D=1e-3;
t=linspace(1e-7,1e-5);
w2n=(n.^2)*pi^2*D/4;
g=((1-(-1).^n)./(n.^2)).*(exp(-w2n.*t)+(k.*(1-(1+w2n.*t).*exp(-w2n.*t)))./(w2n+k.*(1-exp(-w2n.*t))));
sum1 = symsum(g,n,1,250);
plot(t,(1+Cs*(1-(sum1.*4/pi^2))))
Best regards
Stephan

  3 Comments

Interesting this one doesn't have loop either?
he edited this file. Before this code had loop.

Sign in to comment.


Answer by madhan ravi
on 18 Jan 2019

Use symsum() straight away instead of loop.

  1 Comment

Actually I want to do it in for loop

Sign in to comment.