隐函数如何求解?
本帖最后由 ljelly 于 2009-5-12 14:01 编辑小弟初学,遇到下列问题不知如何求解,请高手指教:
a=900;
b=1000;
c=800;
d=600;
e=6000;
h=1800;
eq1='d-c*cos(B)-b*cos(C)+a*cos(A)=0';
eq2='c*sin(B)-b*sin(C)-a*sin(A)=0';
eq3='h-e*sin(C)-a*sin(A)=0';
solve(eq1,eq2,eq3);
上面的程序是想求解出A,B,C的角度,请高手告诉为什么解不出来!
结果为:A=32°,B=61°,C=13° 可能方程太复杂了,试试fsolve数值求解 fsolve我也试过了,解不出来;这个方程复制吗?我感觉这个方程组不是太复杂啊!
matlab应当可以求解的 function test()
x0 = randn(1,3); % Make a starting guess at the solution
options=optimset('Display','iter'); % Option to display output
= fsolve(@myfun,x0,options)% Call optimizer
A=x(1)*180/pi
B=x(2)*180/pi
C=x(3)*180/pi
function F = myfun(x)
a=900;
b=1000;
c=800;
d=600;
e=6000;
h=1800;
F = ;
end
end
A =
32.3635
B =
61.2626
C =
12.6918 小弟初学,遇到下列问题不知如何求解,请高手指教:
a=900;
b=1000;
c=800;
d=600;
e=6000;
h=1800;
eq1='d-c*cos(B)-b*cos(C)+a*cos(A)=0';
eq2='c*sin(B)-b*sin(C)-a*sin(A)=0';
eq3='h-e*sin(C)-a*sin(A ...
昨日的风 发表于 2009-5-12 13:11 http://forum.simwe.com/images/common/back.gif
可以解出来,把系数精简一下,代入方程中
再解方程组,不过,我得到的解很多,也不是这个角度
>> a=9;
b=10;
c=8;
d=6;
e=60;
h=18;
syms A B C
eq1=d-c*cos(B)-b*cos(C)+a*cos(A);
eq2=c*sin(B)-b*sin(C)-a*sin(A);
eq3=h-e*sin(C)-a*sin(A);
>> eq1
eq1 =
6-8*cos(B)-10*cos(C)+9*cos(A)
>> eq2
eq2 =
8*sin(B)-10*sin(C)-9*sin(A)
>> eq3
eq3 =
18-60*sin(C)-9*sin(A)
>> S=solve('6-8*cos(B)-10*cos(C)+9*cos(A)','8*sin(B)-10*sin(C)-9*sin(A)','18-60*sin(C)-9*sin(A)')
S =
A:
B:
C:
>> S1=solve('6-8*cos(B)-10*cos(C)+9*cos(A)=0','8*sin(B)-10*sin(C)-9*sin(A)=0','18-60*sin(C)-9*sin(A)=0')
S1 =
A:
B:
C:
结果显示:
S.A
ans =
.56484878781816786063725321885767
2.9684901527488320105301755967244
-2.5235558588660306634529425604930
-2.0428417723242352007282142196389
.51652934531163299650686398224578-2.0664716503446255250425334003081*i
.51652934531163299650686398224578+2.0664716503446255250425334003081*i
S.B
ans =
1.0692342493630555474888316775144
.56625381267683108184572596335606
-.16902514533103518635567833092830
-2.6636255371872533497509514540560
.59858131023920095338603607205085-2.0535627898405184719899491376255*i
.59858131023920095338603607205085+2.0535627898405184719899491376255*i
S.C
ans =
.22151390178722969707119030021828
2.8638722604087609525933432062284
2.7443085155550950205681138143090
.44847962030892805465613771024160
.25055045597863760182508677847625e-2+.48723508482797825995685557032989*i
.25055045597863760182508677847625e-2-.48723508482797825995685557032989*i
S1.A,S1.B,S1.C 的结果与上面的相同 这个方程不复杂,但好象解很多,说不定收敛到哪一个解 受教了,谢谢大侠啊! function test()
x0 = randn(1,3); % Make a starting guess at the solution
options=optimset('Display','iter'); % Option to display output
= fsolve(@myfun,x0,options)% Call opti ...
akjuan 发表于 2009-5-12 14:24 http://forum.simwe.com/images/common/back.gif
这个解的收敛情况不同
确实存在不同的解
怎么确定哪个是正确的?
楼主给的这个解出现的频率多一些 函数表达式 1: 600-800*cos(x2)-1000*cos(x3)+900*cos(x1)-(0) = 1.970079211E-9
2: 800*sin(x2)-1000*sin(x3)-900*sin(x1)-(0) = -3.593243036E-9
3: 1800-6000*sin(x3)-900*sin(x1)-(0) = -5.418314686E-10
目标函数值(最小): 8.71129235485853E-20
x1: 0.564848787831094
x2: 1.06923424937524
x3: 0.221513901785643 函数表达式 1: 600-800*cos(x2)-1000*cos(x3)+900*cos(x1)-(0) = 1.969851837E-9
2: 800*sin(x2)-1000*sin(x3)-900*sin(x1)-(0) = -3.593015663E-9
3: 1800-6000*sin(x3)-900*sin(x1)-(0) = -5.419451554E-10
目标函数值(最小): 3.37573752151386E-19
x1: 0.564848787831094
x2: -5.21395105780435
x3: 0.221513901785644 函数表达式 1: 600-800*cos(x2)-1000*cos(x3)+900*cos(x1)-(0) = 1.969624464E-9
2: 800*sin(x2)-1000*sin(x3)-900*sin(x1)-(0) = -3.592731446E-9
3: 1800-6000*sin(x3)-900*sin(x1)-(0) = -5.420588423E-10
目标函数值(最小): 1.14453895587537E-19
x1: 0.564848787831092
x2: 7.35241955655482
x3: 0.221513901785644 共有3组解 我用4楼的函数在gui中为什么求解不出来?高手指教一下 不好意思,可能我的问题没有说清楚!
我在pushbutton1下面写如下的回调函数,目的是为了在edit1中显示计算的f值,不知道为什么不可以计算,请高手指教一下!
function test()
x0 = randn(1,3); % Make a starting guess at the solution
options=optimset('Display','iter'); % Option to display output
= fsolve(@myfun,x0,options)% Call optimizer
A=x(1)*180/pi
B=x(2)*180/pi
C=x(3)*180/pi
function F = myfun(x)
a=900;
b=1000;
c=800;
d=600;
e=6000;
h=2200;
F = ;
end
end
f=sin(A)*sin(B)*sin(C);
set(handles.edit1,'string',num2str(f)); 运行下面的代码试试function ceshi
%test program
OldHandle=findobj( 'Type', 'figure', 'Tag', 'ceshi' ) ;
if ishandle( OldHandle )
close( OldHandle ) ;
end
fig=figure ;
init_ceshi(fig) ;
%%-------------------------------------------------------------------------
%initialize
%%-------------------------------------------------------------------------
function init_ceshi(fig)
set(fig,'units','normalized','position',,...
'menubar','none','name','test program',...
'numbertitle','off','color',,'tag','ceshi',...
'resize','off',...
'Interruptible','on');
uimenu(gcf,'Label','help','Callback',...
['nn=sprintf(['' ******test******\n\n'' ',...
' ''**********************************************************\n\n'' ',...
' ''test test test test test\n\n'' ',...
' ''test test test test test'']);'...
'h=msgbox(nn,''help'',''replace'');'])
uimenu(gcf,'Label','about','Callback',...
['nn=sprintf([''test\n\n'' ',...
' ''author:***\n\n'' ',...
' ''QQ:*******\n\n'' ',...
' ''Email:******@******.com\n\n'' ',...
' ''time:200*.*.*\n\n'' ',...
' ''Departments'']);'...
'h=msgbox(nn,''about'',''replace'');'])
uicontrol(gcf,'style','edit','units','normalized',...
'pos',,...
'fontsize',14,'fontunits','normalized',...
'fontweight','bold','string','',...
'tag','edit1','backgroundcolor',);
uicontrol(gcf,'style','push','units','normalized',...
'pos',,...
'string','result',...
'fontsize',14,'fontweight','bold',...
'fontunits','normalized',...
'tag','result',...
'callback',@test);
handles=guihandles(gcf);
guidata(gcf,handles);
%%-------------------------------------------------------------------------
%callback
%%-------------------------------------------------------------------------
function test(hObject, eventdata)
handles=guidata(gcf);
x0 = randn(1,3); % Make a starting guess at the solution
options=optimset('Display','iter'); % Option to display output
a=900;
b=1000;
c=800;
d=600;
e=6000;
h=2200;
myfun=@(x)[d-c*cos(x(2))-b*cos(x(3))+a*cos(x(1));...
c*sin(x(2))-b*sin(x(3))-a*sin(x(1));h-e*sin(x(3))-a*sin(x(1))];
= fsolve(myfun,x0,options)% Call optimizer
A=x(1)*180/pi;
B=x(2)*180/pi;
C=x(3)*180/pi;
f=sin(A)*sin(B)*sin(C);
set(handles.edit1,'string',num2str(f)); 12# wanglei5201118
有没有办法可以只得到我需要的那组解;因为我是通过求解的值去计算其它的方程,如何有三组解的话,极易导致后面方程组解不正确?高手指教一下 15# xiezhh
谢谢xiezhh 的帮助,这个问题已解决了
页:
[1]