problem in solve function

hello I write a m-file that gets the number of equation and solve a system of equation.i use 'solve' function to calculate the roots of system but i get the answer in a structure format and for every roots i must enter the format "q.w1_1" for example. i want to ask how can i get the whole roots in a matrix format?i write the answer of matlab bellow. thank you
q =
w10_1: [1x1 sym]
w10_2: [1x1 sym]
w10_3: [1x1 sym]
w10_4: [1x1 sym]
w10_5: [1x1 sym]
w10_6: [1x1 sym]
w10_7: [1x1 sym]
w10_8: [1x1 sym]
w10_9: [1x1 sym]
w10_10: [1x1 sym]
w1_1: [1x1 sym]
w1_2: [1x1 sym]
w1_3: [1x1 sym]
w1_4: [1x1 sym]
w1_5: [1x1 sym]
w1_6: [1x1 sym]
w1_7: [1x1 sym]
w1_8: [1x1 sym]
w1_9: [1x1 sym]

2 Comments

Can you copy the code here, which gave you that structure? It makes solution easy.
yes.
k=input('enter i and j for calculating w series in form of [i j]');
ww=sym('w',[k(1),k(2)]);
lx=input('enter Lx');
ly=input('enter Ly');
f=input('force?');
syms w0 x y
w0=0;
for i=1:(k(1))
for j=1:(k(2))
w0=w0+ww(i,j)*sin(i*pi*x/lx)*sin(j*pi*y/ly);
end
end
uu=D(1,1)*(diff(w0,x,2))^2+D(2,2)*(diff(w0,y,2))^2+D(3,3)*4*(diff(diff(w0,x),y))^2+2*(D(1,2)*diff(w0,x,2)*diff(w0,y,2)+2*D(3,1)*diff(w0,x,2)*diff(diff(w0,y),x)+2*D(3,2)*diff(w0,y,2)*diff(diff(w0,y),x));
u=.5*int(int(uu,y,0,ly),x,0,lx);
phi=-int(int(w0*f,y,0,ly),x,0,lx);
phiep=u+phi;
for i=1:k(1)
for j=1:k(2)
qq(i,j)=diff(phiep,ww(i,j));
end
end
q=solve(qq)
D(1,2) and other are coefficient that exist from another program

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 6 Jan 2016
Edited: Walter Roberson on 6 Jan 2016
struct2cell(q)
and you might want to cell2mat() the result of that.
But remember that when you do these, you are making a result that depends upon the order of the symbols -- dependent, for example, on the fact that w10_1 sorts before w1_1 because '0' sorts before '_' .

2 Comments

hello thank you for your answer. i do it but there is a error.i type it bellow
aa=struct2cell(q);
>> bb=cell2mat(aa);
Error using cell2mat (line 53)
Cannot support cell arrays containing cell arrays or objects.
If you are looking for the double precision value equivalent then
bb = structfun(@double,q);
If you are looking for the answer still in symbolic form then
aa = struct2cell(q);
bb = vertcat(qq{:});

Sign in to comment.

Categories

Tags

Asked:

on 5 Jan 2016

Commented:

on 6 Jan 2016

Community Treasure Hunt

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

Start Hunting!