I continue to receive an error message when I try to use fsolve. Can anyone tell me what I'm doing wrong? (I'm using MATLAB R2012a)
古いコメントを表示
First I run the following script.
x1 = 15600; y1 = 7540; z1 = 20140;
x2 = 18760; y2 = 2750; z2 = 18610;
x3 = 17610; y3 = 14630; z3 = 13480;
x4 = 19170; y4 = 610; z4 = 18390;
t1 = 0.07074; t2 = 0.07220; t3 = 0.07690; t4 = 0.07242;
c = 299792458;
x0 = [1 1 1 1];
Now my function to find x,y,z, and d.
function F = myfun325_1(x,y,z,d)
F = [sqrt(((x - x(1)).^2) + ((y - y(1)).^2) + ((z - z(1)).^2)) - c*(t(1) - d); sqrt(((x - x(2)).^2) + ((y - y(2)).^2) + ((z - z(2)).^2)) - c*(t(2) - d); sqrt(((x - x(3)).^2) + ((y - y(3)).^2) + ((z - z(3)).^2)) - c*(t(3) - d); sqrt(((x - x(4)).^2) + ((y - y(4)).^2) + ((z - z(4)).^2)) - c*(t(4) - d);];
end
I run the code: fsolve(@myfun325_1,x0) and am returned the following error:
Error using myfun325_1 (line 3) Not enough input arguments.
Error in fsolve (line 241) fuser = feval(funfcn{3},x,varargin{:});
Caused by: Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
採用された回答
その他の回答 (2 件)
Paul
2014 年 2 月 27 日
change all x(1), y(1) etc to x1,y1 etc. Also put:
x1 = 15600; y1 = 7540; z1 = 20140;
x2 = 18760; y2 = 2750; z2 = 18610;
x3 = 17610; y3 = 14630; z3 = 13480;
x4 = 19170; y4 = 610; z4 = 18390;
t1 = 0.07074; t2 = 0.07220; t3 = 0.07690; t4 = 0.07242;
c = 299792458;
inside the function file myfun325_1.
7 件のコメント
Jarrett White
2014 年 2 月 27 日
Paul
2014 年 2 月 27 日
The argument of myfun should be a vector with all the variables inside it. So change the top part of myfun325_1 to:
function F = myfun325_1(xs)
x=xs(1);
y=xs(2);
z=xs(3);
d=xs(4);
Also remove x0=[1 1 1 1]; from inside myfun325_1.
Jarrett White
2014 年 2 月 27 日
Jarrett White
2014 年 2 月 27 日
Jarrett White
2014 年 2 月 27 日
Below is my suggestion for how to rewrite the problem. It basically converts things to more manageable units and gets rid of the sqrt() operations. Without it, you will have points of non-differentiability and also have to worry about the algorithm knowing that c*(t(1) - d) is supposed to be positive.
The rewrite also makes it pretty clear, I think, why the problem has no solution with the data given. The distance of (x,y,z) from (x1,y1,z1) is supposed to be D=c*(t(1) - d). Then the triangle inequality says that the distance from (x2,y2,z2) is at most
D+norm([x1,y1,z1]-[x2,y2,z2]) = D+5.9389
However, your second inequality insists that it be D+q2 = D+437.6970
function F = myfun325_1(p)
x1 = 15.600; y1 = 7.540; z1 = 20.140;
x2 = 18.760; y2 = 2.750; z2 = 18.610;
x3 = 17.610; y3 = 14.630; z3 = 13.480;
x4 = 19.170; y4 = .610; z4 = 18.390;
t1 = 0.07074; t2 = 0.07220; t3 = 0.07690; t4 = 0.07242;
c = 299792.458;
q2=c*(t2-t1);
q3=c*(t3-t1);
q4=c*(t4-t1);
x=p(1); y=p(2); z=p(3); D=p(4);
F = [((x - x1).^2) + ((y - y1).^2) + ((z - z1).^2) - D^2;
((x - x2).^2) + ((y - y2).^2) + ((z - z2).^2) - (D+q2)^2;
((x - x3).^2) + ((y - y3).^2) + ((z - z3).^2) - (D+q3)^2;
((x - x4).^2) + ((y - y4).^2) + ((z - z4).^2) - (D+q4)^2];
カテゴリ
ヘルプ センター および File Exchange で Mathematics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!