I had a problem with the following code. The error says that there are "too many input arguments". I know that the problem is from the fsolve equation but I can't to solve it.

1 ビュー (過去 30 日間)
Mohammed Ashraf
Mohammed Ashraf 2021 年 12 月 2 日
コメント済み: Mohammed Ashraf 2021 年 12 月 2 日
options = optimset('display','off');
for th=0:1:360
theta34(:,i) = fsolve(@position, [1 1],options,th)*180/pi;
function w =position(theta)
w = [+(144*(cos(pi*50/180)))-300+(240*cos(theta(1)))+(241.962*cos(theta(2)));(144*sin(pi*50/180))+(240*sin(theta(1)))-(241.962*sin(theta(2)))];

回答 (2 件)

Walter Roberson
Walter Roberson 2021 年 12 月 2 日
theta34(:,i) = fsolve(@position, [1 1],options,th)*180/pi;
That th after the options struct will be interpreted according to a feature that has not been documented for quite a number of years. For a number of functions that do work on function handles, if you give extra parameters to the master function (fsolve(), fmincon(), ode45() and so on), then the extra parameters will be passed to the function handle.
So as well as the vector of the current theta value being passed to position(), the value of th will be passed as well.
The result is much like
theta34(:,i) = fsolve(@(theta)position)theta,th), [1 1],options)*180/pi;
except that the extra parameters are passed to all of the automatically invoked functions -- including any event functions or plotting functions or nonlinear constraints...
These days, if you want to pass an extra parameter to a function, use parameterization like I show here.
Meanwhile, your position function is not expecting th to be passed in.
  2 件のコメント
Mohammed Ashraf
Mohammed Ashraf 2021 年 12 月 2 日
I am trying to measure the range of values of theta1 and theta2 for a complete revolution. It seems that I was misusing the fsolve function.
Also I can't quite understand the following line of code you used.
theta34(:,i) = fsolve(@(theta)position)theta,th), [1 1],options)*180/pi;


Muhammad Saad
Muhammad Saad 2021 年 12 月 2 日
Sir Walter Roberson, will you please suggest me the matlab code both for segmentation and classfication of mr-brain tumor images of t-2 modality. So, that i can classify the tumor but other than this code ; Brain MRI Tumor Detection and Classification . i will be waiting for your reply. Thanking you in anticipation.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by