声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 685|回复: 1

高手帮忙看看是哪里的问题?

[复制链接]
发表于 2006-5-11 23:02 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
clc;<BR>clear;<BR>R=19880;<BR>a=25.6;<BR>th=2*asin(a/(2*R));<BR>fy=acos(0.5);<BR>for n=1:40<BR>    X(n,1)=R*sin(n*th-th)*cos(0);<BR>    X(n,n)=R*sin(n*th-th)*cos(fy);<BR>    Y(n,1)=R*sin(n*th-th)*sin(0);<BR>    Y(n,n)=R*sin(n*th-th)*sin(fy);<BR>    Z(n,1)=R*cos(n*th-th)-R;<BR>    Z(n,n)=R*cos(n*th-th)-R;<BR>end<BR>for n=3:40<BR>    for m=2:n-1<BR>        x1=X(n-1,m-1);<BR>        x2=X(n-1,m);<BR>        x3=X(n,m-1);<BR>        y1=Y(n-1,m-1);<BR>        y2=Y(n-1,m);<BR>        y3=Y(n,m-1);<BR>        z1=Z(n-1,m-1);<BR>        z2=Z(n-1,m);<BR>        z3=Z(n,m-1);<BR>        fun='(((x1-x(1))^2+(z1-x(3))^2+(y1-x(2))^2)^(1/2)-25.6)^2+(((x2-x(1))^2+(z2-x(3))^2+(y2-x(2))^2)^(1/2)-25.6)^2+(((x3-x(1))^2+(z3-x(3))^2+(y3-x(2))^2)^(1/2)-25.6)^2';     %目标函数<BR>        fun=subs(fun)<BR>        fun=vpa(fun,6)<BR>        x0=[x1 y1 z1-25.6];<BR>        options=foptions;<BR>        options(3)=1e-6;<BR>        A=[ ];   %线性不等式约束<BR>        b=[ ];<BR>        Aeq=[ ];    %无线性等式约束<BR>        beq=[ ];<BR>        lb=[ ];       %x没有下、上界<BR>        ub=[ ];<BR>        [x,fval,exitflag,output,lambda,grad,hessian]=fmincon(fun,x0,A,b,Aeq,beq,lb,ub,@mycon);<BR>        X(n,m)=x(1,1);<BR>        Y(n,m)=x(1,2);<BR>        Z(n,m)=x(1,3);<BR>    end<BR>end<BR><BR>约束条件:x(1)^2+x(2)^2+(x(3)+19880)^2-19880^2=0
回复
分享到:

使用道具 举报

发表于 2006-5-12 08:27 | 显示全部楼层

回复:(creast)高手帮忙看看是哪里的问题?

fun要写成function的形式<BR>具体你看帮助吧<BR><BR>doc fmincon
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-25 19:15 , Processed in 0.068859 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表