From: Walter Roberson on
kp pk wrote:
> Yeah,that works.
> Thanks a lot ,Robert.

"I don't care what the newspapers say about me as long as they spell my name
right." -- variously attributed

( http://www.nku.edu/~turney/prclass/readings/3eras1x.html )
From: kp pk on
er sorry Walter,and thanks again.i have another minor difficulty though,can you help me with that as well?
n=3;
t=0.1;
G=5;
syms x;
syms y;
for i=1:n
pl=(x^2-1)^i;
temp=diff(pl);
for m=1:i-1
temp=diff(temp);
end
f=factorial(i);
P(i)=temp/((2^i)*f);
end
for i=1:n
P(i)=subs(P(i),x,2*y-1);
P(i)=P(i)/sqrt(int(P(i)*P(i),'y',0,1));0
end

syms c;
S=0;
for i=1:n
c(i)=sym(sprintf('c%d',i));
end
for i=1:n
S=S+P(i)*c(i)/t+G*c(i)*diff(P(i));
end
M=coeffs(expand(S),y);

Mc = num2cell(M);
cc = num2cell(c);
D=solve(Mc{:}, cc{:})

now how do i store the values back into c(i),
i cant type out
c(1)=D.c1
c(2)=D.c2
and so on.
because i dont know how many variables the program will be solving for,it depends on 'n' which can be set to any value.
thanks in advance.
From: Walter Roberson on
kp pk wrote:

> Mc = num2cell(M);
> cc = num2cell(c);
> D=solve(Mc{:}, cc{:})
>
> now how do i store the values back into c(i),

Possibly this will work:

c(1:length(Mc)) = structfun(@(x) x, D);

If you get a message about needing UniformOutput set to false, give up on the
above approach.

The above approach has the risk of returning the variables in a different
order than the original, as I am not certain that solve() will create the
field names in the same order as the variables. If this is a concern then,

for K = 1:n
c(K) = D.(sprintf('c%d', K));
end

which should also work if the first approach complains about UniformOutput.
From: kp pk on
the second method works fine.thanks for helping me.
From: kp pk on
n=3;
deltat=0.1;
m=5;
G=5;
syms x;
syms y;
for i=1:n
pl=(x^2-1)^i;
temp=diff(pl);
for m=1:i-1
temp=diff(temp);
end
f=factorial(i);
P(i)=temp/((2^i)*f);
end
for i=1:n
P(i)=subs(P(i),x,2*y-1);
P(i)=P(i)/sqrt(int(P(i)*P(i),'y',0,1));
end
poly(1)=sym(1);
for i=1:n
poly(i+1)=P(i);
end
syms c;
S=0;
for i=1:n
c(i)=sym(sprintf('c%d',i));
temp(i,1)=0;
end
for l=2:m
for i=1:n
S=S+poly(i)*(c(i)-temp(i,l-1))/deltat+G*c(i)*diff(poly(i));
end
M=coeffs(expand(S),y);
Mc = num2cell(M);
cc = num2cell(c);
D=solve(Mc{:}, cc{:});

for K = 1:n
temp(K,l) = D.(sprintf('c%d', K));
end
end

in the above piece of code,when i run it ,i get temp to be
[0,0]
[0,0]
[0,0]
whereas it should be
[0,0,0,0,0]
[0,0,0,0,0]
[0,0,0,0,0]
[0,0,0,0,0]
[0,0,0,0,0]

can you tell me where the loop is going awry?
thanks in advance.