From: Mohammad on 14 Jul 2010 13:13 Hi guys, So usually when I use fzero, I have one variable that I'm trying to solve for. Currently, I still have one variable I want to solve for, but I have other variables I would input myself: f = input('Please enter focal length. [f]: '); h = input('Please enter lens diameter. [h]: '); n = input('Please enter refractive index. [n]: '); z = @(x)(n-1)^2*x/(n(((h/2)^2+(x/2)^2)/x)^2)-1/f; d = fzero(z,2); I'm trying to store a value for d (lens width) but when I run the program I get: FZERO cannot continue because user supplied function_handle ==> @(x)(n-1)^2*x/(n(((h/2)^2+(x/2)^2)/x)^2)-1/f failed with the error below. Attempted to access n(8.5); index must be a positive integer or logical. Error in ==> Narutocool at 6 d = fzero(z,2); A small fix for this would be highly appreciated Cordially, Mohammad
From: Steven Lord on 14 Jul 2010 13:18 "Mohammad " <jaber2(a)uni.uiuc.edu> wrote in message news:i1kr73$b00$1(a)fred.mathworks.com... > Hi guys, > > So usually when I use fzero, I have one variable that I'm trying to solve > for. Currently, I still have one variable I want to solve for, but I have > other variables I would input myself: > > f = input('Please enter focal length. [f]: '); > h = input('Please enter lens diameter. [h]: '); > n = input('Please enter refractive index. [n]: '); > z = @(x)(n-1)^2*x/(n(((h/2)^2+(x/2)^2)/x)^2)-1/f; Did you forget a multiplication sign * immediately before the ((( in this expression? -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
From: Mohammad on 14 Jul 2010 13:32 that fixed it oops... :) Thanks
|
Pages: 1 Prev: solve system of nonlinear equations with fsolve Next: solve |