現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
i Checked calculation and found The solution does not accord with the equation
1 回表示 (過去 30 日間)
古いコメントを表示
i used the matlab to solve the nolinear equation and put the solution in and found The solution does not accord with the equation
codes are as this
function program
function F = root2d(x)
%syms equa1sub equa2sub equa3sub equa4sub equa5sub equa6sub;
equa1sub =x(1)+484533722967603/281474976710656+(4153907340440276559918386333329/10141204801825835211973625643008+43872868936278563423508777924017/40564819207303340847894502572032*i)*x(4)-31910460946994608903643004387955/166153499473114484112975882535043072*x(5)+35907622679629336125438914937027/340282366920938463463374607431768211456*x(6);
equa2sub =x(2)+2179336774425063/9007199254740992-(2329631036423340670360942191305/53099476611423827671670350413824+6151292551464022570539684130455/53099476611423827671670350413824*i)*x(4)+1230493617143412223713722747795/1205242255167036818169426968838144*x(5)-139908178482254182174291657953/1085297737296852063790297074655821824*x(6);
equa3sub =x(3)-2179336774425063/36028797018963968+(17783443026132371529472841155/1491110427947729683792430891008+6151292551464022570539684130455/195335466061152588576808446722048*i)*x(4)+8613455320003885565996059234565/100800544111222430647960069182849024*x(5)+7228589221583132745671735660905/18787405208694330145359816318357864448*x(6);
equa4sub =x(4)+(1160967565235845/562949953421312+5122727319147305/18014398509481984*i)*(-2659506518368929/2251799813685248-43918910449825605755648012145/51854957628343581710615576576*x(2)+17710809864611394710166972861235/18312699943233055179075791880192*x(3));
equa5sub =x(5)+7314742574589651/281474976710656+14883446107327026008787450489355/16091720173204913572666146816*x(2)+15630005759314515809316534852965/48065444999324050258617434112*x(3);
equa6sub =x(6)-8743945551921635/549755813888-40127679390402942495192578739/308460169349260713656320*x(2)+6967229325491925089773435036915/4271761374342152099725312*x(3);
F(1)=equa1sub;
F(2)=equa2sub;
F(3)=equa3sub;
F(4)=equa4sub;
F(5)=equa5sub;
F(6)=equa6sub;
main program
clc;
clear all;
close all;
fun = @root2d;
%x0 = [0,0,0,0,0,0];
x0 = [1,1,1,1,1,1];
%x =fsolve(fun,x0)
x=vpa(fsolve(fun,x0),5)';
alpha0=x(1)
alpha1 = x(2)
alpha2 =x(3)
a0 = x(4)
a1 = x(5)
a2 = x(6)
solutions are as this
Optimization terminated: norm of relative change in X is less
than max(options.TolX^2,eps) and sum-of-squares of function
values is less than sqrt(options.TolFun).
alpha0 =
-3.0311-.40115*i
alpha1 =
-1.4434+.83345*i
alpha2 =
-.89752e-1+.49208e-1*i
a0 =
.28084+1.3447*i
a1 =
1338.2-786.87*i
a2 =
-25475.+28166.*i
>>
but when i put the solution in and found The solution does not accord with the equation
why
2 件のコメント
回答 (2 件)
Walter Roberson
2018 年 12 月 30 日
You have
x=vpa(fsolve(fun,x0),5)';
which takes the solution returned by fsolve, takes the complex conjugate transpose, and truncates it to 5 decimal places. The truncated complex conjugates are not good solutions.
Remember, in MATLAB ' is complex conjugate transpose, not simple transpose.
Note: your functions are linear and so could be solved using \
2 件のコメント
dcydhb dcydhb
2018 年 12 月 31 日
but if i use vpa
i get
alpha0 =
-3.0311 + 0.4012i
if you don't use vpa,you just get
x =
1.0e+004 *
Columns 1 through 4
-0.0003 + 0.0000i
which has a big difference
Walter Roberson
2018 年 12 月 31 日
The problem is the ' not the vpa . You need .' rather than '
x=vpa(fsolve(fun,x0),5).';
Stephan
2018 年 12 月 30 日
編集済み: Stephan
2018 年 12 月 30 日
Hi,
this version works fine for me:
fun = @root2d;
x0 = [1,1,1,1,1,1];
x = fsolve(fun,x0)
result = fun(x)
function F = root2d(x)
%syms equa1sub equa2sub equa3sub equa4sub equa5sub equa6sub;
F(1) =x(1)+484533722967603/281474976710656+(4153907340440276559918386333329/10141204801825835211973625643008+43872868936278563423508777924017/40564819207303340847894502572032*i)*x(4)-31910460946994608903643004387955/166153499473114484112975882535043072*x(5)+35907622679629336125438914937027/340282366920938463463374607431768211456*x(6);
F(2) =x(2)+2179336774425063/9007199254740992-(2329631036423340670360942191305/53099476611423827671670350413824+6151292551464022570539684130455/53099476611423827671670350413824*i)*x(4)+1230493617143412223713722747795/1205242255167036818169426968838144*x(5)-139908178482254182174291657953/1085297737296852063790297074655821824*x(6);
F(3) =x(3)-2179336774425063/36028797018963968+(17783443026132371529472841155/1491110427947729683792430891008+6151292551464022570539684130455/195335466061152588576808446722048*i)*x(4)+8613455320003885565996059234565/100800544111222430647960069182849024*x(5)+7228589221583132745671735660905/18787405208694330145359816318357864448*x(6);
F(4) =x(4)+(1160967565235845/562949953421312+5122727319147305/18014398509481984*i)*(-2659506518368929/2251799813685248-43918910449825605755648012145/51854957628343581710615576576*x(2)+17710809864611394710166972861235/18312699943233055179075791880192*x(3));
F(5) =x(5)+7314742574589651/281474976710656+14883446107327026008787450489355/16091720173204913572666146816*x(2)+15630005759314515809316534852965/48065444999324050258617434112*x(3);
F(6) =x(6)-8743945551921635/549755813888-40127679390402942495192578739/308460169349260713656320*x(2)+6967229325491925089773435036915/4271761374342152099725312*x(3);
end
result is:
Equation solved, fsolve stalled.
fsolve stopped because the relative size of the current step is less than the
default value of the step size tolerance squared and the vector of function values
is near zero as measured by the default value of the function tolerance.
<stopping criteria details>
x =
1.0e+04 *
-0.0003 + 0.0000i -0.0001 - 0.0001i -0.0000 - 0.0000i 0.0000 - 0.0001i 0.1338 + 0.0787i -2.5475 - 2.8166i
result =
1.0e-10 *
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 0.0000i 0.0000 + 0.0000i 0.0014 - 0.0001i 0.0000 + 0.1455i
Best regards
Stephan
23 件のコメント
dcydhb dcydhb
2018 年 12 月 31 日
so do you mean the
x = fsolve(fun,x0)
result = fun(x)
the x is the solution and the result is to put the solution in the equation?
dcydhb dcydhb
2018 年 12 月 31 日
編集済み: dcydhb dcydhb
2018 年 12 月 31 日
and also i put the solution in and the codes are as this
clc;
clear all;
close all;
alpha0 =1.0e+004 *( -0.0003 + 0.0000i );
alpha1 =1.0e+004 *( -0.0001 - 0.0001i);
alpha2 =1.0e+004 *( -0.0000 - 0.0000i );
a0 =1.0e+004 *(0.0000 - 0.0001i);
a1=1.0e+004 *( 0.1338 + 0.0787i );
a2 =1.0e+004 *(-2.5475 - 2.8166i );
x(1)=alpha0;
x(2)=alpha1;
x(3)=alpha2 ;
x(4)= a0 ;
x(5)= a1 ;
x(6)= a2;
x(1)+484533722967603/281474976710656+(4153907340440276559918386333329/10141204801825835211973625643008+43872868936278563423508777924017/40564819207303340847894502572032*i)*x(4)-31910460946994608903643004387955/166153499473114484112975882535043072*x(5)+35907622679629336125438914937027/340282366920938463463374607431768211456*x(6)
x(2)+2179336774425063/9007199254740992-(2329631036423340670360942191305/53099476611423827671670350413824+6151292551464022570539684130455/53099476611423827671670350413824*i)*x(4)+1230493617143412223713722747795/1205242255167036818169426968838144*x(5)-139908178482254182174291657953/1085297737296852063790297074655821824*x(6)
x(3)-2179336774425063/36028797018963968+(17783443026132371529472841155/1491110427947729683792430891008+6151292551464022570539684130455/195335466061152588576808446722048*i)*x(4)+8613455320003885565996059234565/100800544111222430647960069182849024*x(5)+7228589221583132745671735660905/18787405208694330145359816318357864448*x(6)
x(4)+(1160967565235845/562949953421312+5122727319147305/18014398509481984*i)*(-2659506518368929/2251799813685248-43918910449825605755648012145/51854957628343581710615576576*x(2)+17710809864611394710166972861235/18312699943233055179075791880192*x(3))
x(5)+7314742574589651/281474976710656+14883446107327026008787450489355/16091720173204913572666146816*x(2)+15630005759314515809316534852965/48065444999324050258617434112*x(3)
x(6)-8743945551921635/549755813888-40127679390402942495192578739/308460169349260713656320*x(2)+6967229325491925089773435036915/4271761374342152099725312*x(3)
the result
ans =
-0.4567 - 0.5637i
ans =
0.4954 - 0.1490i
ans =
0.0755 + 0.0445i
ans =
-0.9299 + 0.6517i
ans =
4.3907e+002 -1.3791e+002i
ans =
8.8710e+004 +1.0192e+005i
>>
they are not 0
Walter Roberson
2018 年 12 月 31 日
Before you display the values in x, give the command
format long g
Now display x again. You will find some of them are quite different from what you copied.
dcydhb dcydhb
2018 年 12 月 31 日
thanks a lot,it works well,
but why it has a big difference when i use
alpha0 =-3.0311-.40115*i;
alpha1 =-1.4434+.83345*i;
alpha2 =-.89752e-1+.49208e-1*i;
a0 =.28084+1.3447*i;
a1 =1338.2-786.87*i;
a2 =-25475.+28166.*i;
i get
ans =
-2.90871132396907 + 0.607484578051479i
ans =
0.311531099632365 - 0.0650666606923589i
ans =
-0.0846890466989907 + 0.0176878639974451i
ans =
0.374490074032625 - 0.0258183590976351i
ans =
-0.0183929950145583 + 0.00053882521234172i
ans =
6.98186657158658 + 0.322983928941539i
>>
and when i use your format long,use
alpha0 = -3.0311134536181 + 0.401152454231559i;
alpha1 = -1.44335136284869 - 0.833446193001501i;
alpha2 = -0.0897522685127253 - 0.0492077544975424i;
a0 =0.280837251730613 - 1.34470093706138i;
a1=1338.17349516203 + 786.866937848724i;
a2 = -25475.2167010186 - 28165.5821761859i;
i get
ans =
7.16657636012918e-015 - 9.82720849140861e-016i
ans =
-3.83026943495679e-015 + 2.64979010955457e-016i
ans =
1.43982048506075e-016 - 4.85722573273506e-017i
ans =
7.43849426498855e-015 - 3.10862446895044e-015i
ans =
-3.29336558024806e-012 - 8.88178419700125e-014i
ans =
4.94765117764473e-010 - 4.36557456851006e-011i
>>
Walter Roberson
2018 年 12 月 31 日
You took the complex conjugate at some point by using ' instead of .'
dcydhb dcydhb
2019 年 1 月 1 日
編集済み: dcydhb dcydhb
2019 年 1 月 1 日
i mean if i don't use the format long,i get the answer
alpha0 =-3.0311-.40115*i;
alpha1 =-1.4434+.83345*i;
alpha2 =-.89752e-1+.49208e-1*i;
a0 =.28084+1.3447*i;
a1 =1338.2-786.87*i;
a2 =-25475.+28166.*i;
if i use format long,i get
alpha0 = -3.0311134536181 + 0.401152454231559i;
alpha1 = -1.44335136284869 - 0.833446193001501i;
alpha2 = -0.0897522685127253 - 0.0492077544975424i;
a0 =0.280837251730613 - 1.34470093706138i;
a1=1338.17349516203 + 786.866937848724i;
a2 = -25475.2167010186 - 28165.5821761859i;
and when i put the soution in the equation,the former has the Precision
such as
ans =
6.98186657158658 + 0.322983928941539i
while the latter has the Precision such as
ans =
4.94765117764473e-010 - 4.36557456851006e-011i
why has a big difference
dcydhb dcydhb
2019 年 1 月 1 日
codes are as this
using format long ,i get the answer
alpha0 = -3.0311134536181 + 0.401152454231559i;
alpha1 = -1.44335136284869 - 0.833446193001501i;
alpha2 = -0.0897522685127253 - 0.0492077544975424i;
a0 =0.280837251730613 - 1.34470093706138i;
a1=1338.17349516203 + 786.866937848724i;
a2 = -25475.2167010186 - 28165.5821761859i;
and put it in the program
clc;
clear all;
close all;
alpha0 =-0.902612530938861 + 2.16356827387381i;
alpha1 = -0.18816334103255 - 0.122205949485723i;
alpha2 = 0.0572191359187823 + 0.040682702643867i;
a0 = 2.03364667845748 - 0.0196408376693919i;
a1 = 129.438386669641 + 99.7957252883904i;
a2 = -101899.136979033 - 82252.7316082889i;
x(1)=alpha0;
x(2)=alpha1;
x(3)=alpha2 ;
x(4)= a0 ;
x(5)= a1 ;
x(6)= a2;
equa1sub =x(1)+484533722967603/281474976710656-(4154756651791824122955846205623/10141204801825835211973625643008+10968068365840776354319913193387/10141204801825835211973625643008*i)*x(4)+15954949269969134648023144147861/83076749736557242056487941267521536*x(5)-71813660819499486824121496911249/680564733841876926926749214863536422912*x(6)
equa2sub =x(2)+2179336774425063/9007199254740992+(37526423397676813332334898889027/855220629711474430592113990172672+49532669641878859065350990413901/427610314855737215296056995086336*i)*x(4)-7398539084151252801240731883817/7245856949184205584664105964273664*x(5)+9701869628173919811376223237191/75261204389257980309851363976180400128*x(6)
equa3sub =x(3)-2179336774425063/36028797018963968-(12508807799225604444111632963009/1048697196988140797536670555570176+49532669641878859065350990413901/1573045795482211196305005833355264*i)*x(4)-7398539084151252801240731883817/86588217623736540910447134758666240*x(5)-29105608884521759434128669711573/75649093851100752735482115538246696960*x(6)
equa4sub =x(4)+(2322028850419079/1125899906842624+2562706364895407/9007199254740992*i)*(-5318998413755481/4503599627370496-2829251784246184997786270102985/3340705584810446994500445274112*x(2)+1485584096701532954999143830883/1536177534650596871391607259136*x(3))
equa5sub =x(5)+1828304033752709/70368744177664+798857101094098914621327367885/863773459098840425570500608*x(2)+3355712380299671672017873907067/10322119906394069303327457280*x(3)
equa6sub =x(6)-8744181223955479/549755813888-8904871213428984377698427416207/68449666641079584505724928*x(2)+56109258842949034654051535392393/34401225025749569220116480*x(3)
i get
equa1sub =
4.7011e-016 +3.7643e-015i
equa2sub =
-1.0582e-016 +3.4694e-017i
equa3sub =
2.2898e-016 -2.0817e-017i
equa4sub =
-4.4409e-016 -2.8103e-016i
equa5sub =
-6.7146e-013 +1.1191e-013i
equa6sub =
-2.4738e-010 -7.2760e-011i
>>
while when don't use format long
i get the answer
alpha0 =-3.0311-.40115*i;
alpha1 =-1.4434+.83345*i;
alpha2 =-.89752e-1+.49208e-1*i;
a0 =.28084+1.3447*i;
a1 =1338.2-786.87*i;
a2 =-25475.+28166.*i;
and put it in the program
clc;
clear all;
close all;
alpha0 =-3.0311-.40115*i;
alpha1 =-1.4434+.83345*i;
alpha2 =-.89752e-1+.49208e-1*i;
a0 =.28084+1.3447*i;
a1 =1338.2-786.87*i;
a2 =-25475.+28166.*i;
x(1)=alpha0;
x(2)=alpha1;
x(3)=alpha2 ;
x(4)= a0 ;
x(5)= a1 ;
x(6)= a2;
equa1sub =x(1)+484533722967603/281474976710656-(4154756651791824122955846205623/10141204801825835211973625643008+10968068365840776354319913193387/10141204801825835211973625643008*i)*x(4)+15954949269969134648023144147861/83076749736557242056487941267521536*x(5)-71813660819499486824121496911249/680564733841876926926749214863536422912*x(6)
equa2sub =x(2)+2179336774425063/9007199254740992+(37526423397676813332334898889027/855220629711474430592113990172672+49532669641878859065350990413901/427610314855737215296056995086336*i)*x(4)-7398539084151252801240731883817/7245856949184205584664105964273664*x(5)+9701869628173919811376223237191/75261204389257980309851363976180400128*x(6)
equa3sub =x(3)-2179336774425063/36028797018963968-(12508807799225604444111632963009/1048697196988140797536670555570176+49532669641878859065350990413901/1573045795482211196305005833355264*i)*x(4)-7398539084151252801240731883817/86588217623736540910447134758666240*x(5)-29105608884521759434128669711573/75649093851100752735482115538246696960*x(6)
equa4sub =x(4)+(2322028850419079/1125899906842624+2562706364895407/9007199254740992*i)*(-5318998413755481/4503599627370496-2829251784246184997786270102985/3340705584810446994500445274112*x(2)+1485584096701532954999143830883/1536177534650596871391607259136*x(3))
equa5sub =x(5)+1828304033752709/70368744177664+798857101094098914621327367885/863773459098840425570500608*x(2)+3355712380299671672017873907067/10322119906394069303327457280*x(3)
equa6sub =x(6)-8744181223955479/549755813888-8904871213428984377698427416207/68449666641079584505724928*x(2)+56109258842949034654051535392393/34401225025749569220116480*x(3)
and i get
equa1sub =
0.2893 - 1.4099i
equa2sub =
-2.7146 + 1.7321i
equa3sub =
-0.2158 + 0.0807i
equa4sub =
0.3744 - 0.0258i
equa5sub =
0.0813 - 0.0599i
equa6sub =
8.9329 - 1.1249i
>>
which has a big difference comparing with the format long
Walter Roberson
2019 年 1 月 1 日
Are you still using your posted main program,
clc;
clear all;
close all;
fun = @root2d;
%x0 = [0,0,0,0,0,0];
x0 = [1,1,1,1,1,1];
%x =fsolve(fun,x0)
x=vpa(fsolve(fun,x0),5)';
alpha0=x(1)
alpha1 = x(2)
alpha2 =x(3)
a0 = x(4)
a1 = x(5)
a2 = x(6)
If so then you need to correct the line
x=vpa(fsolve(fun,x0),5)';
to
x=vpa(fsolve(fun,x0),5).';
dcydhb dcydhb
2019 年 1 月 1 日
so do you mean it is not the precision but the Conjugate?
x=vpa(fsolve(fun,x0),5).';
your method really solve the problem but why using vpa,it appears the Conjugate problem?
Walter Roberson
2019 年 1 月 1 日
The vpa() gives some inaccuracy, but it is the complex conjugate that was really messing things up for you.
dcydhb dcydhb
2019 年 1 月 1 日
thanks a lot,the question ahs been solevd but another question appears,
when i increase the Expansion item number,form 6 equations to 12 equations,
codes are as this
function codes
function F = root2d(x)
%syms equa1sub equa2sub equa3sub equa4sub equa5sub equa6sub;
equa1sub =x(1)+484533722967603/281474976710656-(4154756651791824122955846205623/10141204801825835211973625643008+10968068365840776354319913193387/10141204801825835211973625643008*i)*x(7)+15954949269969134648023144147861/83076749736557242056487941267521536*x(8)-71813660819499486824121496911249/680564733841876926926749214863536422912*x(9)+68704458373558018815486967994675/1393796574908163946345982392040522594123776*x(10)-26218118780833903306440628355937/1427247692705959881058285969449495136382746624*x(11)+206796938269122258779026599337/91343852333181432387730302044767688728495783936*x(12);
equa2sub =x(2)+2179336774425063/9007199254740992+(37526423397676813332334898889027/855220629711474430592113990172672+49532669641878859065350990413901/427610314855737215296056995086336*i)*x(7)-7398539084151252801240731883817/7245856949184205584664105964273664*x(8)+9701869628173919811376223237191/75261204389257980309851363976180400128*x(9)-1277211448906621552448654388595/23860751773952951312363398400278311993344*x(10)+1362802704850279953288683880255/70907773931469299065694310054832901202116608*x(11)-8625402993825599933615303699537/3702438626946186324992873082646789575845217304576*x(12);
equa3sub =x(3)-2179336774425063/36028797018963968-(12508807799225604444111632963009/1048697196988140797536670555570176+49532669641878859065350990413901/1573045795482211196305005833355264*i)*x(7)-7398539084151252801240731883817/86588217623736540910447134758666240*x(8)-29105608884521759434128669711573/75649093851100752735482115538246696960*x(9)+1277211448906621552448654388595/17711241862742021199068701875804540239872*x(10)-1362802704850279953288683880255/61068558073531812431847844722400210020466688*x(11)+8625402993825599933615303699537/3380027201713290762974992106633635151204912726016*x(12);
equa4sub =x(4)+7748752975733557/288230376151711744+(33356820797934943209001720132433/6190408764194964734552061289431040+22014519840835049131921318329153/1547602191048741183638015322357760*i)*x(7)+26305916743648898510433925203569/863922993464667543602663285577482240*x(8)-51743304683594236328831377155201/310355742240037684763822436037613846528*x(9)-36329570102232795753818397281155/212254113490217598493003436507731431784448*x(10)+19382082913426203433050528326643/635304746339119300790994312862157102563459072*x(11)-2555674961133510611575096049613/842274022614853767674660051874414976259181248512*x(12);
equa5sub =x(5)-2179336774425063/144115188075855872-(37526423397676813332334898889027/12309575435976212511299345462591488+49532669641878859065350990413901/6154787717988106255649672731295744*i)*x(7)-7398539084151252801240731883817/461924515915419508444148023940874240*x(8)+29105608884521759434128669711573/524888983415592000040805790022931316736*x(9)-1277211448906621552448654388595/6886797782101713761219919597640643248128*x(10)-151422522761142217032075986695/2412410515753537353989004504838094190542848*x(11)+8625402993825599933615303699537/2090381500781707541347807227300837103175632683008*x(12);
equa6sub =x(6)+5579102142528161/576460752303423488+(37526423397676813332334898889027/19182188319735057694389731174907904+49532669641878859065350990413901/9591094159867528847194865587453952*i)*x(7)+7398539084151252801240731883817/743426739634181641860703322279772160*x(8)-29105608884521759434128669711573/975292541365611677959817308065299955712*x(9)+1277211448906621552448654388595/25335327515734513772510566088095356157952*x(10)-454267568283426651096227960085/2601984310676884475399766100960607803015168*x(11)-8625402993825599933615303699537/1123147225083019881738503323981193479786657218560*x(12);
equa7sub =x(7)+(2322028850419079/1125899906842624+2562706364895407/9007199254740992*i)*(-5318998413755481/4503599627370496-11316947028382809420225314005533/13362822339241787978001781096448*x(2)+47539893266487660052480027409623/49157681108819099884531432292352*x(3)-9653174320626376094416784221761/9672513694054632397737595764736*x(4)+48624853531325315583340957398461/48084279046782080122263068213248*x(5)-19076967537554081507840067761767/18732605780991267279677471850496*x(6));
equa8sub =x(8)+1828304033752709/70368744177664+12781645729332806833062081373649/13820375345581446809128009728*x(2)+41947465506445508270841202315/129026498829925866291593216*x(3)-106470105689011260713633181571/402295493271512698197114880*x(4)+143015982726173118919053113709/573600972587142771040583680*x(5)-21546008834667373653917509482703/88623373464844422562206187520*x(6);
equa9sub =x(9)-8744181223955479/549755813888-53428943499171695984835881591627/410697999846477507034349568*x(2)+56110677749960030092146867614297/34401225025749569220116480*x(3)+28483769964134474313932345620805/17641681452007428831838208*x(4)-14347810331846682779060483651413/14918242169858103808360448*x(5)+22516280630792217615492161016547/27719481220333695943049216*x(6);
equa10sub =x(10)+2143354288027763/268435456+76889959165422172751349313276095/1324537800215405753532416*x(2)-40374630662549725282540084069465/122896428192007114981376*x(3)+40991188782415858629190320752825/23012637096507873427456*x(4)+13765354859219285845701862029855/3982229928972283543552*x(5)-64806667879765933354102588502575/43949787413105820565504*x(6);
equa11sub =x(11)-1743625504902557/524288-683191558149789503090357463411/29326767937702191104*x(2)+22959445633915007586210679339785/202058909099976753152*x(3)-11655028849494739207651118904051/32844485577164910592*x(4)+652317456398320801335468445423/498874802037594112*x(5)+383885133922523724333435256089/67259717998721024*x(6);
equa12sub =x(12)+3878949580580463/8192+19055803659565858140764297628659/5841418173556017152*x(2)-10006131399781328118029811914599/666592829503797504*x(3)+20317868644705667433246067365239/498327785943072384*x(4)-5117246172621763207417567132397/51531882592622344*x(5)+16061175637909210839969990512723/55375433542216160*x(6);
F(1)=equa1sub;
F(2)=equa2sub;
F(3)=equa3sub;
F(4)=equa4sub;
F(5)=equa5sub;
F(6)=equa6sub;
F(7)=equa7sub;
F(8)=equa8sub;
F(9)=equa9sub;
F(10)=equa10sub;
F(11)=equa11sub;
F(12)=equa12sub;
main program codes
clc;
clear all;
close all;
fun = @root2d;
x0 = [1,1,1,1,1,1,1,1,1,1,1,1];
format long g
x = fsolve(fun,x0);
result = fun(x);
alpha0=x(1)
alpha1 = x(2)
alpha2 =x(3)
alpha3=x(4)
alpha4 = x(5)
alpha5 =x(6)
a0 = x(7)
a1 = x(8)
a2 = x(9)
a3 = x(10)
a4 = x(11)
a5 = x(12)
i get 12 roots,but when i put the answers in and the answer doesn't satisify the equation and why?
i didn't use the vpa
and the hints are as this
Maximum number of function evaluations reached:
increase options.MaxFunEvals.
dcydhb dcydhb
2019 年 1 月 1 日
so how to set the options
such as this?
options= struct('MaxFunEvals',10000,'MaxIter', 10000);
x = fsolve(fun,x0,options);
Walter Roberson
2019 年 1 月 1 日
編集済み: Walter Roberson
2019 年 1 月 1 日
You have the Symbolic Toolbox, use it.
X = sym('x', [1 12]);
[A, b] = equationsToMatrix(root2d(X));
x = A\b;
xd = double(x);
Note that your matrix is singular to within double precision:
rank(double(A)) % -> 6
rank(A) % -> 12
This is because you add some relatively small values.
Your code is misleading you about how much precision is available. You have obviously converted it from symbolic code without taking into account that numeric code does not have that much precision. You should go back to symbolic code:
function F = root2d(x)
S = @(v) sym(v);
equa1sub =x(1)+S('484533722967603')/S('281474976710656')-S('4154756651791824122955846205623')/S('10141204801825835211973625643008')+S('10968068365840776354319913193387')/S('10141204801825835211973625643008')*1i*x(7)+S('15954949269969134648023144147861')/S('83076749736557242056487941267521536')*x(8)-S('71813660819499486824121496911249')/S('680564733841876926926749214863536422912')*x(9)+S('68704458373558018815486967994675')/S('1393796574908163946345982392040522594123776')*x(10)-S('26218118780833903306440628355937')/S('1427247692705959881058285969449495136382746624')*x(11)+S('206796938269122258779026599337')/S('91343852333181432387730302044767688728495783936')*x(12);
equa2sub =x(2)+S('2179336774425063')/S('9007199254740992')+S('37526423397676813332334898889027')/S('855220629711474430592113990172672')+S('49532669641878859065350990413901')/S('427610314855737215296056995086336')*1i*x(7)-S('7398539084151252801240731883817')/S('7245856949184205584664105964273664')*x(8)+S('9701869628173919811376223237191')/S('75261204389257980309851363976180400128')*x(9)-S('1277211448906621552448654388595')/S('23860751773952951312363398400278311993344')*x(10)+S('1362802704850279953288683880255')/S('70907773931469299065694310054832901202116608')*x(11)-S('8625402993825599933615303699537')/S('3702438626946186324992873082646789575845217304576')*x(12);
equa3sub =x(3)-S('2179336774425063')/S('36028797018963968')-S('12508807799225604444111632963009')/S('1048697196988140797536670555570176')+S('49532669641878859065350990413901')/S('1573045795482211196305005833355264')*1i*x(7)-S('7398539084151252801240731883817')/S('86588217623736540910447134758666240')*x(8)-S('29105608884521759434128669711573')/S('75649093851100752735482115538246696960')*x(9)+S('1277211448906621552448654388595')/S('17711241862742021199068701875804540239872')*x(10)-S('1362802704850279953288683880255')/S('61068558073531812431847844722400210020466688')*x(11)+S('8625402993825599933615303699537')/S('3380027201713290762974992106633635151204912726016')*x(12);
equa4sub =x(4)+S('7748752975733557')/S('288230376151711744')+S('33356820797934943209001720132433')/S('6190408764194964734552061289431040')+S('22014519840835049131921318329153')/S('1547602191048741183638015322357760')*1i*x(7)+S('26305916743648898510433925203569')/S('863922993464667543602663285577482240')*x(8)-S('51743304683594236328831377155201')/S('310355742240037684763822436037613846528')*x(9)-S('36329570102232795753818397281155')/S('212254113490217598493003436507731431784448')*x(10)+S('19382082913426203433050528326643')/S('635304746339119300790994312862157102563459072')*x(11)-S('2555674961133510611575096049613')/S('842274022614853767674660051874414976259181248512')*x(12);
equa5sub =x(5)-S('2179336774425063')/S('144115188075855872')-S('37526423397676813332334898889027')/S('12309575435976212511299345462591488')+S('49532669641878859065350990413901')/S('6154787717988106255649672731295744')*1i*x(7)-S('7398539084151252801240731883817')/S('461924515915419508444148023940874240')*x(8)+S('29105608884521759434128669711573')/S('524888983415592000040805790022931316736')*x(9)-S('1277211448906621552448654388595')/S('6886797782101713761219919597640643248128')*x(10)-S('151422522761142217032075986695')/S('2412410515753537353989004504838094190542848')*x(11)+S('8625402993825599933615303699537')/S('2090381500781707541347807227300837103175632683008')*x(12);
equa6sub =x(6)+S('5579102142528161')/S('576460752303423488')+S('37526423397676813332334898889027')/S('19182188319735057694389731174907904')+S('49532669641878859065350990413901')/S('9591094159867528847194865587453952')*1i*x(7)+S('7398539084151252801240731883817')/S('743426739634181641860703322279772160')*x(8)-S('29105608884521759434128669711573')/S('975292541365611677959817308065299955712')*x(9)+S('1277211448906621552448654388595')/S('25335327515734513772510566088095356157952')*x(10)-S('454267568283426651096227960085')/S('2601984310676884475399766100960607803015168')*x(11)-S('8625402993825599933615303699537')/S('1123147225083019881738503323981193479786657218560')*x(12);
equa7sub =x(7)+S('2322028850419079')/S('1125899906842624')+S('2562706364895407')/S('9007199254740992')*1i-S('5318998413755481')/S('4503599627370496')-S('11316947028382809420225314005533')/S('13362822339241787978001781096448')*x(2)+S('47539893266487660052480027409623')/S('49157681108819099884531432292352')*x(3)-S('9653174320626376094416784221761')/S('9672513694054632397737595764736')*x(4)+S('48624853531325315583340957398461')/S('48084279046782080122263068213248')*x(5)-S('19076967537554081507840067761767')/S('18732605780991267279677471850496')*x(6);
equa8sub =x(8)+S('1828304033752709')/S('70368744177664')+S('12781645729332806833062081373649')/S('13820375345581446809128009728')*x(2)+S('41947465506445508270841202315')/S('129026498829925866291593216')*x(3)-S('106470105689011260713633181571')/S('402295493271512698197114880')*x(4)+S('143015982726173118919053113709')/S('573600972587142771040583680')*x(5)-S('21546008834667373653917509482703')/S('88623373464844422562206187520')*x(6);
equa9sub =x(9)-S('8744181223955479')/S('549755813888')-S('53428943499171695984835881591627')/S('410697999846477507034349568')*x(2)+S('56110677749960030092146867614297')/S('34401225025749569220116480')*x(3)+S('28483769964134474313932345620805')/S('17641681452007428831838208')*x(4)-S('14347810331846682779060483651413')/S('14918242169858103808360448')*x(5)+S('22516280630792217615492161016547')/S('27719481220333695943049216')*x(6);
equa10sub =x(10)+S('2143354288027763')/S('268435456')+S('76889959165422172751349313276095')/S('1324537800215405753532416')*x(2)-S('40374630662549725282540084069465')/S('122896428192007114981376')*x(3)+S('40991188782415858629190320752825')/S('23012637096507873427456')*x(4)+S('13765354859219285845701862029855')/S('3982229928972283543552')*x(5)-S('64806667879765933354102588502575')/S('43949787413105820565504')*x(6);
equa11sub =x(11)-S('1743625504902557')/S('524288')-S('683191558149789503090357463411')/S('29326767937702191104')*x(2)+S('22959445633915007586210679339785')/S('202058909099976753152')*x(3)-S('11655028849494739207651118904051')/S('32844485577164910592')*x(4)+S('652317456398320801335468445423')/S('498874802037594112')*x(5)+S('383885133922523724333435256089')/S('67259717998721024')*x(6);
equa12sub =x(12)+S('3878949580580463')/S('8192')+S('19055803659565858140764297628659')/S('5841418173556017152')*x(2)-S('10006131399781328118029811914599')/S('666592829503797504')*x(3)+S('20317868644705667433246067365239')/S('498327785943072384')*x(4)-S('5117246172621763207417567132397')/S('51531882592622344')*x(5)+S('16061175637909210839969990512723')/S('55375433542216160')*x(6);
F(1)=equa1sub;
F(2)=equa2sub;
F(3)=equa3sub;
F(4)=equa4sub;
F(5)=equa5sub;
F(6)=equa6sub;
F(7)=equa7sub;
F(8)=equa8sub;
F(9)=equa9sub;
F(10)=equa10sub;
F(11)=equa11sub;
F(12)=equa12sub;
You will still have the problem that rank(double(A)) is only 6, but the code I post here with equationsToMatrix will work fine with it.
dcydhb dcydhb
2019 年 1 月 2 日
are you really sure this will work?
i get the hints
??? Error using ==> error
Formatted arguments cannot be non-scalar numeric matrices.
Error in ==> sym.sym at 100
error('symbolic:sym:sym:errmsg4','Second argument %s not recognized.',a);
Error in ==> Untitled2 at 5
X = sym('x', [1 12]);
dcydhb dcydhb
2019 年 1 月 2 日
and also i think it is not a convenient way to use for example you have to edit a lot in the function programs such as this,yu have to change the function program to this form
equa1sub =x(1)+S('484533722967603')/S('281474976710656')-S('4154756651791824122955846205623')/S('10141204801825835211973625643008')+S('10968068365840776354319913193387')/S('10141204801825835211973625643008')*1i*x(7)+S('15954949269969134648023144147861')/S('83076749736557242056487941267521536')*x(8)-S('71813660819499486824121496911249')/S('680564733841876926926749214863536422912')*x(9)+S('68704458373558018815486967994675')/S('1393796574908163946345982392040522594123776')*x(10)-S('26218118780833903306440628355937')/S('1427247692705959881058285969449495136382746624')*x(11)+S('206796938269122258779026599337')/S('91343852333181432387730302044767688728495783936')*x(12);
Walter Roberson
2019 年 1 月 2 日
are you really sure this will work?
That syntax has been supported since R2010b. I see that you are using R2007a, which was still based on Maple rather than the MuPAD that has been used since R2008a+ and later. You will probably need to do something like:
for K = 1 : 12
X(K) = sym( sprintf('x%d', K) );
end
i think it is not a convenient way to use
It is obvious that you are generating expressions such as x(1)+484533722967603/281474976710656 instead of coding them by hand. Change how you generate them, keeping in mind that for the range of values you are using, you are suffering badly from round-off error.
It looks to me as if you have very likely attempted to use floating point mixed with symbolic variables when you generated those expressions. For example you might have something like
G = 338.7;
H = 28399.4;
solve( an expression in G/H*x )
and are expecting to get sensible answers out of it.
However, it is a almost always a categorical error to use floating point constants together with solve() or any symbolic operation. What does G = 338.7 mean ? Does it mean exactly 3387/10 ? Does it mean "some number between 338.65 inclusive and 338.75 exclusive that got rounded to 338.7" ?
If you have a floating point constant that has a precise definition such as 1.8 in temperature conversion being defined as being exactly 9/5, then use sym(9)/sym(5) rather than 1.8 . And be consistent about it. For example, 1.8*1.414*x is not the same as sym(1.8)*sym(1.414) which is not the same as sym(9)/sym(5) * sqrt(sym(2))
If you have floating point numbers such as 1.602E-19 that are approximations rather than exact definitions, then you should not be using solve() with them -- not unless you are deliberately coding to take into account interval arithmetic based upon the known uncertainties in the numbers.
Remember that solve() is for finding indefinitely precise solutions according to theory. It is a mistake to ask for an indefinitely precise solution based upon formula numbers that are not themselves indefinitely precise.
dcydhb dcydhb
2019 年 1 月 2 日
you have mentioned a way
X = sym('x', [1 12]);
[A, b] = equationsToMatrix(root2d(X));
x = A\b;
xd = double(x);
to solve the equation,and i got the answers and put them in to the equation and they are still not the root of the equation
12 equations are as this ,maybe you could try to solve it,thanks a lot
function F = root2d(x)
%syms equa1sub equa2sub equa3sub equa4sub equa5sub equa6sub;
equa1sub =x(1)+484533722967603/281474976710656-(4154756651791824122955846205623/10141204801825835211973625643008+10968068365840776354319913193387/10141204801825835211973625643008*i)*x(7)+15954949269969134648023144147861/83076749736557242056487941267521536*x(8)-71813660819499486824121496911249/680564733841876926926749214863536422912*x(9)+68704458373558018815486967994675/1393796574908163946345982392040522594123776*x(10)-26218118780833903306440628355937/1427247692705959881058285969449495136382746624*x(11)+206796938269122258779026599337/91343852333181432387730302044767688728495783936*x(12);
equa2sub =x(2)+2179336774425063/9007199254740992+(37526423397676813332334898889027/855220629711474430592113990172672+49532669641878859065350990413901/427610314855737215296056995086336*i)*x(7)-7398539084151252801240731883817/7245856949184205584664105964273664*x(8)+9701869628173919811376223237191/75261204389257980309851363976180400128*x(9)-1277211448906621552448654388595/23860751773952951312363398400278311993344*x(10)+1362802704850279953288683880255/70907773931469299065694310054832901202116608*x(11)-8625402993825599933615303699537/3702438626946186324992873082646789575845217304576*x(12);
equa3sub =x(3)-2179336774425063/36028797018963968-(12508807799225604444111632963009/1048697196988140797536670555570176+49532669641878859065350990413901/1573045795482211196305005833355264*i)*x(7)-7398539084151252801240731883817/86588217623736540910447134758666240*x(8)-29105608884521759434128669711573/75649093851100752735482115538246696960*x(9)+1277211448906621552448654388595/17711241862742021199068701875804540239872*x(10)-1362802704850279953288683880255/61068558073531812431847844722400210020466688*x(11)+8625402993825599933615303699537/3380027201713290762974992106633635151204912726016*x(12);
equa4sub =x(4)+7748752975733557/288230376151711744+(33356820797934943209001720132433/6190408764194964734552061289431040+22014519840835049131921318329153/1547602191048741183638015322357760*i)*x(7)+26305916743648898510433925203569/863922993464667543602663285577482240*x(8)-51743304683594236328831377155201/310355742240037684763822436037613846528*x(9)-36329570102232795753818397281155/212254113490217598493003436507731431784448*x(10)+19382082913426203433050528326643/635304746339119300790994312862157102563459072*x(11)-2555674961133510611575096049613/842274022614853767674660051874414976259181248512*x(12);
equa5sub =x(5)-2179336774425063/144115188075855872-(37526423397676813332334898889027/12309575435976212511299345462591488+49532669641878859065350990413901/6154787717988106255649672731295744*i)*x(7)-7398539084151252801240731883817/461924515915419508444148023940874240*x(8)+29105608884521759434128669711573/524888983415592000040805790022931316736*x(9)-1277211448906621552448654388595/6886797782101713761219919597640643248128*x(10)-151422522761142217032075986695/2412410515753537353989004504838094190542848*x(11)+8625402993825599933615303699537/2090381500781707541347807227300837103175632683008*x(12);
equa6sub =x(6)+5579102142528161/576460752303423488+(37526423397676813332334898889027/19182188319735057694389731174907904+49532669641878859065350990413901/9591094159867528847194865587453952*i)*x(7)+7398539084151252801240731883817/743426739634181641860703322279772160*x(8)-29105608884521759434128669711573/975292541365611677959817308065299955712*x(9)+1277211448906621552448654388595/25335327515734513772510566088095356157952*x(10)-454267568283426651096227960085/2601984310676884475399766100960607803015168*x(11)-8625402993825599933615303699537/1123147225083019881738503323981193479786657218560*x(12);
equa7sub =x(7)+(2322028850419079/1125899906842624+2562706364895407/9007199254740992*i)*(-5318998413755481/4503599627370496-11316947028382809420225314005533/13362822339241787978001781096448*x(2)+47539893266487660052480027409623/49157681108819099884531432292352*x(3)-9653174320626376094416784221761/9672513694054632397737595764736*x(4)+48624853531325315583340957398461/48084279046782080122263068213248*x(5)-19076967537554081507840067761767/18732605780991267279677471850496*x(6));
equa8sub =x(8)+1828304033752709/70368744177664+12781645729332806833062081373649/13820375345581446809128009728*x(2)+41947465506445508270841202315/129026498829925866291593216*x(3)-106470105689011260713633181571/402295493271512698197114880*x(4)+143015982726173118919053113709/573600972587142771040583680*x(5)-21546008834667373653917509482703/88623373464844422562206187520*x(6);
equa9sub =x(9)-8744181223955479/549755813888-53428943499171695984835881591627/410697999846477507034349568*x(2)+56110677749960030092146867614297/34401225025749569220116480*x(3)+28483769964134474313932345620805/17641681452007428831838208*x(4)-14347810331846682779060483651413/14918242169858103808360448*x(5)+22516280630792217615492161016547/27719481220333695943049216*x(6);
equa10sub =x(10)+2143354288027763/268435456+76889959165422172751349313276095/1324537800215405753532416*x(2)-40374630662549725282540084069465/122896428192007114981376*x(3)+40991188782415858629190320752825/23012637096507873427456*x(4)+13765354859219285845701862029855/3982229928972283543552*x(5)-64806667879765933354102588502575/43949787413105820565504*x(6);
equa11sub =x(11)-1743625504902557/524288-683191558149789503090357463411/29326767937702191104*x(2)+22959445633915007586210679339785/202058909099976753152*x(3)-11655028849494739207651118904051/32844485577164910592*x(4)+652317456398320801335468445423/498874802037594112*x(5)+383885133922523724333435256089/67259717998721024*x(6);
equa12sub =x(12)+3878949580580463/8192+19055803659565858140764297628659/5841418173556017152*x(2)-10006131399781328118029811914599/666592829503797504*x(3)+20317868644705667433246067365239/498327785943072384*x(4)-5117246172621763207417567132397/51531882592622344*x(5)+16061175637909210839969990512723/55375433542216160*x(6);
F(1)=equa1sub;
F(2)=equa2sub;
F(3)=equa3sub;
F(4)=equa4sub;
F(5)=equa5sub;
F(6)=equa6sub;
F(7)=equa7sub;
F(8)=equa8sub;
F(9)=equa9sub;
F(10)=equa10sub;
F(11)=equa11sub;
F(12)=equa12sub;
dcydhb dcydhb
2019 年 1 月 3 日
編集済み: dcydhb dcydhb
2019 年 1 月 3 日
i have used this
for K = 1 : 12
X(K) = sym( sprintf('x%d', K) );
end
[A, b] = equationsToMatrix(root2d(X), X);
%[A, b] = equationsToMatrix(root2d(X));
x = A\b;
xd = double(x);
conj(vpa(x,10))
it has the best result but still has some difference,put the root in the equation i got some are still not zero
equa1sub =
0.8957 - 0.0963i
equa2sub =
-0.1504 - 0.2645i
equa3sub =
0.0261 - 0.0028i
equa4sub =
-0.0185 - 0.0325i
equa5sub =
0.0067 - 0.0007i
equa6sub =
-0.0067 - 0.0118i
equa7sub =
-3.0071 + 0.0878i
equa8sub =
-1.0658e-014 -3.2196e-015i
equa9sub =
-3.0923e-011 +4.0927e-012i
equa10sub =
0
equa11sub =
0
equa12sub =
9.7656e-004 -1.2207e-004i
>>
dcydhb dcydhb
2019 年 1 月 3 日
編集済み: dcydhb dcydhb
2019 年 1 月 3 日
without conj(x) there is more difference,and still i need the effective way to get the root of the 12 equations
dcydhb dcydhb
2019 年 1 月 3 日
編集済み: dcydhb dcydhb
2019 年 1 月 3 日
this time i use this
for K = 1 : 12
X(K) = sym( sprintf('x%d', K) );
end
[A, b] = equationsToMatrix(root2d(X), X);
%[A, b] = equationsToMatrix(root2d(X));
x = A\b;
xd = double(x);
vpa(x,10)
i put the root in the equation and get
equa1sub =
0.3873 + 2.6626i
equa2sub =
-0.0959 - 0.0103i
equa3sub =
0.0113 + 0.0775i
equa4sub =
-0.0118 - 0.0013i
equa5sub =
0.0029 + 0.0198i
equa6sub =
-0.0043 - 0.0005i
equa7sub =
-2.9789 - 0.5863i
equa8sub =
-5.7895e-008 -8.8981e-009i
equa9sub =
6.1587e-006 -8.7048e-006i
equa10sub =
0.0054 + 0.0038i
equa11sub =
38.2471 + 0.8511i
equa12sub =
1.4872e+003 +2.0583e+002i
>>
they are not zero so is the way effiective to solve the equation?
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)