Need help to form equations

조회 수: 1 (최근 30일)
Sameer
Sameer 2014년 6월 6일
편집: Sameer 2014년 6월 6일
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