MATLAB 板


LINE

是要把以下程式修改成2 variable并解出 4.*x.^2-20.*x+1/4.*y.^2+8=0 1/2.*x.*y+2.*x-5.*y+8=0 求近似值 但是我要哪里修改成二元二次的联立方程? 以下为m档 小的是非常新的新手还请大大有点耐心教导 谢谢 function steepest(ff) n=input('输入方程式数目n='); ii=0; for i=1:n fprintf('输入初始值x(%d):',i); x0(i)=input(''); end tol=input('输入允许误差tol='); maxit=input('输入最大计算次数maxit='); fprintf(' k x(1) x(2) x(3) SO\n'); k=0; % fprintf('%d %f %f %f %f\n',k,x0(1),x0(2),x0(3),s0); while (1) y=feval(ff,x0); s0=y(1).^2+y(2).^2+y(3).^2;%fprintf('s0=%f\n',s0); fprintf('%d %f %f %f %f\n',k,x0(1),x0(2),x0(3),s0); t(1)=0; h(1)=s0; xr=x0; xr(1)=xr(1)+0.0001; yx=feval(ff,xr); sx=yx(1).^2+yx(2).^2+yx(3).^2; sxx=(sx-s0)/0.0001;%fprintf('sxx=%f\n',sxx); xr=x0; xr(2)=xr(2)+0.0001; yy=feval(ff,xr); sy=yy(1).^2+yy(2).^2+yy(3).^2; syy=(sy-s0)/0.0001;%fprintf('syy=%f\n',syy); xr=x0; xr(3)=xr(3)+0.0001; yz=feval(ff,xr); sz=yz(1).^2+yz(2).^2+yz(3).^2; szz=(sz-s0)/0.0001;%fprintf('szz=%f\n',szz); M=sqrt(sxx.^2+syy.^2+szz.^2);%fprintf('M=%f\n',M); if abs(M)<=0.000001 %fprintf('ans=%f break; end ir=1;iim=0; t(3)=1.0; %while(ir>=1) xt(1)=x0(1)-t(3).*sxx/M; xt(2)=x0(2)-t(3).*syy/M; xt(3)=x0(3)-t(3).*szz/M; y=feval(ff,xt); h(3)=y(1).^2+y(2).^2+y(3).^2;%fprintf('h(1)=%f,h(3)=%f\n',h(1),h(3)); while(ir>=1) ir=0; if abs(h(3))>=abs(h(1)) t(3)=t(3)/2; if t(3)<0.00001 %fprintf('t(3)is too small...\n');iim=1; break; end ir=1; end xt(1)=x0(1)-t(3).*sxx/M; xt(2)=x0(2)-t(3).*syy/M; xt(3)=x0(3)-t(3).*szz/M; y=feval(ff,xt); h(3)=y(1).^2+y(2).^2+y(3).^2;%fprintf('h(1)=%f,h(3)=%f\n',h(1),h(3)); end if iim==1 break; end t(2)=t(3)/2; h(1)=s0; xt(1)=x0(1)-t(2).*sxx/M; xt(2)=x0(2)-t(2).*syy/M; xt(3)=x0(3)-t(2).*szz/M; y=feval(ff,xt); h(2)=y(1).^2+y(2).^2+y(3).^2; p1=(h(2)-h(1))/(t(2)-t(1)); p2=(h(3)-h(2))/(t(3)-t(2)); p3=(p2-p1)/(t(3)-t(1)); t(4)=0.5.*(t(1)+t(2)-p1/p3); xt(1)=x0(1)-t(4).*sxx/M; xt(2)=x0(2)-t(4).*syy/M; xt(3)=x0(3)-t(4).*szz/M; y=feval(ff,xt); h(4)=y(1).^2+y(2).^2+y(3).^2;%fprintf('h(1)=%f,h(2)=%f,h(3)=%f,h(4)=%f\n',h(1),h(2),h(3),h(4)); min=h(1);%fprintf('t(1)=%f,t(2)=%f,t(3)=%f,t(4)=%f\n',t(1),t(2),t(3),t(4)); kk=1; for j=1:4 if h(j)<min min=h(j); kk=j; end end tt=t(kk);hh=h(kk);%fprintf('tt=%f\n',tt); xt(1)=x0(1)-tt.*sxx/M; xt(2)=x0(2)-tt.*syy/M; xt(3)=x0(3)-tt.*szz/M; %fprintf('hh=%f,xt(1)=%f,xt(2)=%f,xt(3)=%f,so=%f\n',hh,xt(1),xt(2),xt(3),so); if abs(hh-h(1))<0.0001 break; end k=k+1; if k>=maxit break; end x0=xt; %fprintf('%d %f %f %f %f\n',k,x0(1),x0(2),x0(3),s0); end --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 123.192.77.189
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/MATLAB/M.1402500511.A.1C1.html







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Tech_Job站内搜寻

TOP