i want to solve a 10 equation, 10 states with fsolve , but it does not give me the answer.

1 次查看(过去 30 天)
HI Guys. Actually I want t o test that is there a 4x4 matrix named P which is positive and A1'*P+P1*A1 and also A2'*P+P1*A2 are negative matrixes?
May you please guide me how can I test/ do that?
Firstly I try to solve a 2x2 matrix P with Fsolve in a way that A1'*P+P*A1=-eye(2,2) , and see is there any positive p that gives me this result, but actually the bellow code that I wrote does not give me any solution. Why?
And I will be thankful if any one can help me in my problem in 4x4 matrix A1,A2 that I write in my mfile.
clear all;
clc;
close all;
A1=[3.4*10^-15 7.6*10^-6;1 4];
%A1=[3.4*10^-15 7.6*10^-6 0 0;-4*10^-16 -6.5*10^-5 0 0;2.3*10^-16 0.00059 -0.1426 0;-8.159*10^-14 -0.05 18.21 0.08];
A2=[9.04*10^-7 -1.48*10^-6 0 0;-1.977*10^-7 -1.008*10^-5 0 0;9.24*10^-8 0.00045 -0.127 0;-8.55*10^-5 -0.10 65.217 -0.0833];
syms p1
syms p2
syms p3
syms p4
syms p5
syms p6
syms p7
syms p8
syms p9
syms p10
%P=[p1 p2 p3 p4;p2 p5 p6 p7;p3 p6 p8 p9;p4 p7 p9 p10];
P=[p(1) p(2);p(2) p(3)];
p(1)>0;
det(P)>0;
function F = myfun(p)
F=A1'*P+P*A1+eye(2,2)=0;
p0=[1 1;1 1];
[p,fval]=solve(@myfun,p0)
  4 个评论
Walter Roberson
Walter Roberson 2019-4-12
azam ghamari comments to John D'Errico
Ok, I want to solve firstly this problem (fsolve) and then my initial question. Thanks

请先登录,再进行评论。

采纳的回答

azam ghamari
azam ghamari 2019-4-12
thank you, but no it gives me this error:
Error: File: Untitled2.m Line: 8 Column: 1
Function definitions are not permitted in this context.
and also after solving this, do you have any suggestion for the other part ?" Actually I want t o test that is there a 4x4 matrix named P which is positive and A1'*P+P1*A1 and also A2'*P+P1*A2 are negative matrixes.", I brout A1,A2 also in my mfile.
Thank you

更多回答(2 个)

Walter Roberson
Walter Roberson 2019-4-12
A1=[3.4*10^-15 7.6*10^-6;1 4];
%A1=[3.4*10^-15 7.6*10^-6 0 0;-4*10^-16 -6.5*10^-5 0 0;2.3*10^-16 0.00059 -0.1426 0;-8.159*10^-14 -0.05 18.21 0.08];
A2=[9.04*10^-7 -1.48*10^-6 0 0;-1.977*10^-7 -1.008*10^-5 0 0;9.24*10^-8 0.00045 -0.127 0;-8.55*10^-5 -0.10 65.217 -0.0833];
P = sym('p', [1 3]);
sol = solve(myfun(P,A1));
p = vpa([sol.p1, sol.p2, sol.p3]);
disp(p)
function F = myfun(p, A1)
P=[p(1) p(2);p(2) p(3)];
F=A1'*P+P*A1+eye(2,2);
end
  17 个评论
azam ghamari
azam ghamari 2019-4-17
Dear Mr Walter
I wrote the solve function but it gives me this error:
Error using solve (line 268)
Specify a variable for which you solve.
Error in sample (line 15)
sol=solve(myfun(P,A1));
(I write the myfun in another mfile and copy it below the main program)
clear all;
clc;
close all;
sym p(1)
sym p(2)
sym p(3)
sym P
A1=[3.4*10^-15 7.6*10^-6;1 4];
p0=[1 -0.5;1 -0.1];
[P,fval]=fsolve(@(P) myfun(P,A1),p0);
sol=solve(myfun(P,A1));
p=vpa([sol.p(1),sol.p(2),sol.p(3)]);
display (P);
-------------------------------------
function F = myfun(p,A1)
P=[p(1) p(2);p(2) p(3)];
F=A1'*P+P*A1+eye(2,2);
end
Walter Roberson
Walter Roberson 2019-4-17
When you did the fsolve(), you overwrote the P variable that I had created by
P = sym('p', [1 3]);
Use a different output variable for fsolve(), or at least postpone the fsolve() until after the solve()
Note: those lines with sym p(1) and so on are wrong and will cause an error. You will also find that sol.p does not have 3 entries.
I do not know why you insist on breaking the working code that I give you.

请先登录,再进行评论。


azam ghamari
azam ghamari 2019-4-17
no I write you code exactly and I comment the line fsolve, wrongly it's written here. However I write your code:
with this myfun code:
function F = myfun(p,A1)
P=[p(1) p(2);p(2) p(3)];
F=A1'*P+P*A1+eye(2,2);
end
but it gives me this error:
Reference to non-existent field 'p'.
Error in sample (line 16)
p=vpa([sol.p(1),sol.p(2),sol.p(3)]);
clear all;
clc;
close all;
A1=[3.4*10^-15 7.6*10^-6;1 4];
P=sym('p',[1 3]);
p0=[1 -0.5;1 -0.1];
%[P,fval]=fsolve(@(P) myfun(P,A1),p0);
sol=solve(myfun(P,A1));
p=vpa([sol.p(1),sol.p(2),sol.p(3)]);
display (P);
  2 个评论
Walter Roberson
Walter Roberson 2019-4-17
https://www.mathworks.com/matlabcentral/answers/455900-i-want-to-solve-a-10-equation-10-states-with-fsolve-but-it-does-not-give-me-the-answer#comment_693628 and notice I refer to sol.p1 not sol.p(1)
azam ghamari
azam ghamari 2019-4-17
ok, thanks very much, it works.
so this equations is better to solve with solve not fsolve.... so which equation we can solve from fsolve? (if we know the answer that we start from around that work, it is solved, but we don't know the answer at all. it is the problem)
thanks

请先登录,再进行评论。

类别

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

标签

产品


版本

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by