MATLAB: Need help to form equations

equations

Hello all
I want to form the equations through the matlab commands,I have the matrix of constants….Can anyone guide how can I form the equations. Example equations
1) a1v1^2-a2v2-a3v3^2-a4v4=0
2) a3v3^2-a4v4-a1v1=0
3) a1v1+a4v4-a3v3^2=0
4) a2v2+a1v1+a3v3-a4v4=0
where a's are constant and I have a matrix for a and I have to find v's.
I want to use them in fsolve.
please guide!!!
Regards

Best Answer

a = rand(1,4); % your a matrix
syms v1 v2 v3 v4
S = solve( a(1)*v1^2-a(2)*v2-a(3)*v3^2-a(4)*v4==0,...
a(3)*v3^2-a(4)*v4-a(1)*v1==0,...
a(1)*v1+a(4)*v4-a(3)*v3^2==0,...
a(2)*v2+a(1)*v1+a(3)*v3-a(4)*v4==0)
S =
v1: [4x1 sym]
v2: [4x1 sym]
v3: [4x1 sym]
v4: [4x1 sym]
To display the solutions, access the elements of the structure array S
S.v1
ans =
0
0.76082746713182598996024745838092
- 0.38041373356591299498012372919046 - 0.65889591443313132581875790778993*i
- 0.38041373356591299498012372919046 + 0.65889591443313132581875790778993*i