|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
写的MATLAB代码,最小二乘求距离出现错误,麻烦大神帮忙看看,非常感谢!8 M7 _& k+ {3 o" p( s* v4 {
, }$ x i) k" j3 cclc;2 {( j+ y% B. t* y. @7 r' r
clear all;6 E1 C; q+ @6 C1 s" I. P& `% k
A=[1 2 3;3 4 5;6 7 8;6 7 8;6 7 8;11 12 14;22 23 43;1 2 3;3 4 5;6 7 8;6 7 8;6 7 8;11 12 14;22 23 43;1 2 3;3 4 5;6 7 8;6 7 8;6 7 8;11 12 14;22 23 43];$ Z$ c% P1 L X6 t
P=[1 2 3 4 5 6 7 9 11 81 2 9 32 21 5 6 7 9 11 81 2];* |/ G( p6 J' |( G' M. N/ J
0 e& s8 y. C$ ~8 F+ F( R$ E2 l
c=3*10^8;
M, l' @9 d& t- Y( JX=zeros(4,1);0 \1 [' |: V/ i4 J0 M
x=zeros(4,1);
$ }3 _. ^7 I7 n+ j. _for i=1:1:21
% a o% Z! t, W Ri=sqrt((A(i,1)-x(1,1)).^2+(A(i,2)-x(2,1)).^2+(A(i,3)-x(3,1)).^2);, e& p' C1 T5 r" `0 U4 ~8 D
p(i,1)=Ri+x(4,1)-P(i,1);& {0 S# ^) d: ~/ E7 h
' i7 M; I4 b3 a# n fxi=(A(i,1)-x(1,1))/Ri;* ]4 p. I6 G/ d. N4 Z+ d
fyi=(A(i,2)-x(2,1))/Ri;& p! R( g# {, R% } [" A# K
fzi=(A(i,3)-x(3,1))/Ri;
6 r' Q9 b. d: u F(i,: )=[fxi fyi fzi -c];4 W" R5 M+ w8 |: ]# b# S- w& l
. T- P8 E- S! k; |5 J
syms x0 y0 z0 t0 real;
; O1 G' f* g' O" M% X. w X=[x0 y0 z0 t0]';- v b) Z! K- |) }( R4 T
; `3 a4 U5 p3 U* k: e& N
p(i,1)=F(i,: )*X;
5 @+ e q+ R/ a" Y ^1 F. o1 V7 b7 |0 e) X' }& t0 K* \
x(1,1)=x(1,1)+x0;. g3 M" i- [% m' S+ b8 C; O
x(2,1)=x(2,1)+y0;5 Z! J% m4 M# G( i
x(3,1)=x(3,1)+z0;5 X$ a% m* x$ Y( w# @
x(4,1)=x(4,1)+t0;
F2 l$ d8 m) A) o6 v- i/ M8 hend @1 q$ g1 \# q( j3 H8 D
0 F6 s! D% e" W$ A
figure(1);4 z+ C5 A+ L8 ?. ?
plot(x0,'r-');
; a& _! ?2 L9 F6 Rhold on;
. x. x: P9 c; k+ |' k6 Nfigure(2);
2 f# |7 D+ i& y! k- O" B5 d# [" F' H. `' Mplot(y0,'g*');, s/ H- `6 J" `
hold on;+ m) e- g" P* a7 m% v
figure(3);
1 A8 x$ ^0 A% G/ ?% fplot(z0,'b-');7 {' Z7 v' ^- Y) R
hold on;
' h/ J7 A3 l' Q6 Y: `0 Pxlabel('X');
& i" X- J( D2 ~& e5 b5 wxlabel('Y');
+ z! y9 j* E/ o, dlegend('measurement');
; Q; A" @' z# Y% h9 h7 d
9 u4 v: T) y7 D0 V* Y- v, Y4 C
- ?& G! U! r) K- v5 T6 r; G
, D& v* b% C. }8 U编译出现错误:
$ c! g H7 s) \5 R3 h7 l错误使用 symengine (line 58), l, D9 r- ]0 j& G
DOUBLE cannot convert the input expression into a double array.( A# a& @8 u$ a8 t$ M' \% V* K
If the input expression contains a symbolic variable, use VPA.
" a, o5 _7 K/ k2 q$ f! R0 ?
3 n `0 _4 I, b4 Z出错 zxec (line 21)% A- V+ G/ f2 p) r" n
p(i,1)=F(i,: )*X;
6 U; k; X6 i3 c6 c$ C6 F! V |
|