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

1 view (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 12 Apr 2019
azam ghamari comments to John D'Errico
Ok, I want to solve firstly this problem (fsolve) and then my initial question. Thanks

Sign in to comment.

Accepted Answer

azam ghamari
azam ghamari on 12 Apr 2019
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

More Answers (2)

Walter Roberson
Walter Roberson on 12 Apr 2019
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 Comments
azam ghamari
azam ghamari on 17 Apr 2019
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 on 17 Apr 2019
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.

Sign in to comment.


azam ghamari
azam ghamari on 17 Apr 2019
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 Comments
Walter Roberson
Walter Roberson on 17 Apr 2019
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 on 17 Apr 2019
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

Sign in to comment.

Tags

Products


Release

R2014a

Community Treasure Hunt

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

Start Hunting!