fsolve will not work on my machine

I have been trying to get fsolve to work on my personal computer. I have tried many different problems and all come out with the same error. "Error using fsolve. Too many input arguments." I have ultimately dumbed down my problem to solve to the code at the end to make sure it isn't a coding error. This code works perfectly on the school's computer but not on my own. I have checked and I do have the optimization toolbox installed. Other functions in the optimization toolbox work, such as fmincon. I have tried uninstalling and reinstalling the optimization toolbox. I have also uninstalled and reinstalled matlab. I am using version 2018b but have also tried using 2017b on my personal computer but neither work. Is there something that I am missing. This is a fairly straight forward function.
Thanks for your help.
clc;
x0=0;
x=fsolve(@test,x0);
function F=test(x)
F=2*x+1;
end

댓글 수: 4

Odd. Well, show us the result that you see when doing
>> which -all fsolve
Even going back to r2006a, fsolve() has always allowed up to 3 inputs. So that rule out one possibility.
Perhaps you have a different function on your matlab path named fsolve()? To check that run this line. If you have more than 1 file named fsolve() it will appear in the output.
which fsolve -all
% C:\Program Files\MATLAB\R2018a\toolbox\optim\optim\fsolve.m
Justin Becker
Justin Becker 2019년 4월 3일
편집: Justin Becker 2019년 4월 3일
The output I get from the above code is below.
Apparently there was a file I didn't know about called fsolve that it was trying to run. Thanks for your help guys!
Error using fsolve
Too many input arguments.
Error in myFunction (line 4)
x=fsolve(@test,x0);
Adam Danz
Adam Danz 2019년 4월 3일
편집: Adam Danz 2019년 4월 3일
Nice! Either re-name the other fsolve() function or remove its path prior to calling the built-in fsolve() function.
rmpath('C:\Users\name\Documents\MATLAB\myPoorlyNamedFunctions\fsolve.m')

댓글을 달려면 로그인하십시오.

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 4월 4일
편집: KALYAN ACHARJYA 2019년 4월 4일

0 개 추천

Do the following;
  1. Save the function named as test.m
function F=test(x)
F=2*x+1;
end
2. Call the function from different main script or command window
clc;
x0=0;
x=fsolve(@(x) test(x),x0);
There may be same function name conflict, so change the function name in all three position.
  1. Change function name
  2. Change in save Matlab file name
  3. During Call the function name
All must be tthe same name.
Or
As @Adam suggested to avoid the conflict the file name with inbuilt function (fsolve)
pppp.png
Hope it Helps!

카테고리

도움말 센터File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

2019년 4월 3일

편집:

2019년 4월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by