使用优化工具箱是时问题。
Show older comments
我用matlab的优化app来求解一个非线性最小二乘法问题主函数:
close all; clear; clc;
x=-3:1:3
y=-2:1:2
[X,Y]= meshgrid(x,y)
Z=X.^2+Y.^2
mesh(X,Y,Z)
hold on
d=1/180*pi
e=2/180*pi
f=3/180*pi
T=[1,0,0,0
0,1,0,0
0,0,1,0
0.1,0.2,0.3,1]
R1=[1,0,0,0
0,cos(d),sin(d),0
0,(-1)*sin(d),cos(d),0
0,0,0,1];
R2=[cos(e),0,(-1)*sin(e),0
0,1,0,0
sin(e),0,cos(e),0
0,0,0,1];
R3=[cos(f),sin(f),0,0
(-1)*sin(f),cos(f),0,0
0,0,1,0
0,0,0,1];
t=size(X,1)*size(X,2);
W=[X(:),Y(:),Z(:),ones(t,1)]*T*R1*R2*R3;
global X2
global Y2
global Z2
X2=W(:,1)
Y2=W(:,2)
Z2=W(:,3)
plot3(X2,Y2,Z2)
函数文件:
function [n,x1,x2,x3] = obj(a,x,y,z)
%UNTITLa(5)a(4)4 此处显示有关此函数的摘要
% 此处显示详细说明
T=[1,0,0,0
0,1,0,0
0,0,1,0
a(1),a(2),a(3),1];
R1=[1,0,0,0
0,cos(a(4)),sin(a(4)),0
0,(-1)*sin(a(4)),cos(a(4)),0
0,0,0,1];
R2=[cos(a(5)),0,(-1)*sin(a(5)),0
0,1,0,0
sin(a(5)),0,cos(a(5)),0
0,0,0,1];
R3=[cos(a(6)),sin(a(6)),0,0
(-1)*sin(a(6)),cos(a(6)),0,0
0,0,1,0
0,0,0,1];
w=[x,y,z,1]*R3*R2*R1*T;
x1=w(:,1);
x2=w(:,2);
x3=w(:,3);
n=x3-x1^2-x2^2;
使用优化app时的报错如图:我检查过没有上述说的括号的问题,实在不知道怎么回事了,请赐教!

Accepted Answer
More Answers (0)
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!