Prev: FZERO Error
Next: FZERO Error plus matrx dimensions
From: Kyle on 29 Mar 2010 23:25 I cannot figure out why I keep getting this error: ??? Error using ==> fzero FZERO cannot continue because user supplied function_handle ==> @(Velocity)(0.5*C_D1*p*A_o*(Velocity^2)*((1000^2)/(3600^2)))+F_grav+F_rolling+Force_Car failed with the error below. Error using ==> plus Matrix dimensions must agree. here is part of my code: fun=@(t)8*x*(t^2)+Growth+Length+Width x = fzero(fun,1) Where growth, length, and width are the result of other equations in my code. I have this code in a for loop to find the value at which this function is zero at 30 different values for a particular parameter that each equation is dependent upon. What am I doing wrong?
From: Matt Fig on 30 Mar 2010 00:03 Seems to work here. % Data Growth = 7; Length = 5; Width = 3; x = -1; % Find new x fun=@(t)8*x*(t^2)+Growth+Length+Width x = fzero(fun,1) x = 1.36930639376292
From: Kyle on 30 Mar 2010 00:13 Well, growth, width, and length are arbitrary equations that are matrices in my actual code. I guess I'm confused on why exactly I'm getting the error and what it means.
From: Kyle on 30 Mar 2010 00:46 I think I found where I my error is. Growth is a 20X1 matrix while length and width are both 12X1 matrices. Any suggestions on how to tackle this?
From: Matt Fig on 30 Mar 2010 00:53
Well, like was mentioned in another of your threads, fun must take scalar inputs and return a scalar. % Data, based on latest information Growth = rand(2); Length = rand(2); Width = rand(2); x = -1; fun=@(t)8*x*(t^2)+Growth+Length+Width % Run and check if fun takes a scalar (it does) and returns a scalar (it doesn't). >> fun(4) ans = -126.104734437492 -126.555874461904 -126.615771738023 -126.243465573257 So it takes a scalar, but does not return a scalar. You may need to break the function down even further. |