Need help to form equations

1 次查看(过去 30 天)
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

采纳的回答

David Sanchez
David Sanchez 2014-6-6
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
  2 个评论
Sameer
Sameer 2014-6-6
Hello...thanks for replying but my concern is that i have plenty of equations,thus i want to generate the equations using a loop,therefore i want to know how can I acheive that...
Awaiting a response
Regards
Sameer
Sameer 2014-6-6
To give the more clear idea:
function F = Equation_trial( x )
F= [50-20*x(1)-30*x(2)-40*x(3);
30*x(2)-50*x(4)-60*x(5);
20*x(1)+60*x(5)-70*x(6);
70*x(6)+50*x(4)+40*x(3)-80*x(7);
50000+20-x(8)-500*x(1)^2;
50000+20-x(9)-500*x(2)^2;
50000+20-x(10)-500*x(3)^2;
500*x(2)^2+x(9)-x(11)-500*x(4)^2;
500*x(2)^2+x(9)-x(12)-500*x(5)^2;
500*x(6)^2+x(13)-x(8)-500*x(1)^2;
500*x(6)^2+x(13)-x(12)-500*x(5)^2;
500*x(7)^2+x(14)-x(10)-500*x(3)^2;
500*x(7)^2+x(14)-x(11)-500*x(4)^2;
500*x(7)^2+x(14)-x(13)-500*x(6)^2];
end
x0=[1,1,1,1,1,1,1,1,1,1,1,1,1,1]'
[x,fval]=fsolve(@Equation_trial,x0)
This is what I have to do but I want these equations to be generated on its own using a loop.
please quide
regards

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by