r1=0.1
r2=0.15
r3=0.12
r=0.12
vol1=0.08
vol2=0.18
vol3=0.20
cor12=0.7
cor13=0.1
cor23=0.4
syms delta1 delta2 delta3 lamda1 lamda2
L=((vol1^2*delta1^2+vol2^2*delta2^2+vol3^2*delta3^2+...
2*delta1*delta2*vol1*vol2*cor12+...
2*delta1*delta3*vol1*vol3*cor13+...
2*delta2*delta3*vol2*vol3*cor23)-...
lamda1(delta1*r1+delta2*r2+delta3*r3-r)-...
lamda2(delta1+delta2+delta3-1))
d1=diff(L,delta1)
d2=diff(L,delta2)
d3=diff(L,delta3)
d4=diff(L,lamda1)
d5=diff(L,lamda2)
s=solve(d1,d2,d3,d4,d5)
s1=s.delta1
s2=s.delta2
s3=s.delta3