From: kp pk on 5 Jul 2010 17:13 n=20; 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)); 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+1)-c(i))/t+G*c(i)*diff(P(i)); end M=coeffs(expand(S),y); This is the program im running. M is now a array with 20 elements,each of which are equations in c1,c2,c3,..,c20 Now i want to equate each of these equations to 0 and solve for c1,c2,...c20. can anyone suggest a way to do this? thanks.
From: Walter Roberson on 5 Jul 2010 17:32 kp pk wrote: > M is now a array with 20 elements,each of which are equations in > c1,c2,c3,..,c20 > Now i want to equate each of these equations to 0 and solve for > c1,c2,...c20. > can anyone suggest a way to do this? Possibly solve(M,c) I do not have the symbolic toolbox to cross-check this with.
From: kp pk on 5 Jul 2010 17:50 no walter,i already tried that.that doesnt work.
From: Walter Roberson on 5 Jul 2010 18:23 kp pk wrote: > no walter,i already tried that.that doesnt work. Hmmm... then the following might work: Mc = num2cell(M); cc = num2cell(c); solve(Mc{:}, cc{:}) The documentation for num2cell is contradictory: it says in some places that it works for numeric arrays but there is a specific line in the documentation saying that it works for all array types. If num2cell does not work then, Mc = cell(numel(M),1); cc = cell(numel(c),1); for K = 1 : numel(M) Mc{K} = M(K); end for K = 1 : numel(c) cc{K} = c(K); end solve(Mc{:}, cc{:})
From: kp pk on 6 Jul 2010 12:55
Yeah,that works. Thanks a lot ,Robert. |