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 visualizzazione (ultimi 30 giorni)
i=1;
options = optimset('display','off');
for th=0:1:360
the(i)=th;
theta34(:,i) = fsolve(@position, [1 1],options,th)*180/pi;
i=i+1;
end
plot(the(1,:),theta34(1,:));
hold;
plot(the(1,:),theta34(2,:));
grid;
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)))];
end

Risposte (2)

Walter Roberson
Walter Roberson il 2 Dic 2021
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 Commenti
Walter Roberson
Walter Roberson il 2 Dic 2021
As you are not passing th into position, then you are seeming to want to solve according to a number of different initial positions, which would seem to call for passing in some values derived from theta as the initial positions. Here I choose initializating as th/5 and th/7 becaused that gave an interesting result that some of the other things I tried did not give.
i=1;
options = optimset('display','off');
for th=0:1:360
the(i)=th;
theta34(:,i) = fsolve(@position, [th/5, th/7],options)*180/pi;
i=i+1;
end
plot(the(1,:),theta34(1,:));
hold;
Current plot held
plot(the(1,:),theta34(2,:));
grid;
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)))];
end
Mohammed Ashraf
Mohammed Ashraf il 2 Dic 2021
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;

Accedi per commentare.


Muhammad Saad
Muhammad Saad il 2 Dic 2021
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