Info

This question is closed. Reopen it to edit or answer.

How can I solve an equation with variables?

1 view (last 30 days)
Renata Ruskova
Renata Ruskova on 8 Sep 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
I have a problem when I want to use variables in function. I'm using Matlab version R2013a (8.1.0.604) There is a simplified example of this problem:
function main
syms x
a=5;
b=3;
c=fsolve(@ff,1);
end
function F=ff(x,a,b);
F=a*x-b*x+1;
end
Matlab's answer: Not enough input arguments (line 9) Error in fsolve fuser=feval(funfcn{3},x,varargin{:}); Error in c=fsolve(@ff,1); Caused by: Failure in initial user/supplied objective function evaluation. FSOLVE cannot continue.
Thank you for solving this problem.

Answers (1)

Sean de Wolski
Sean de Wolski on 8 Sep 2014
I think you want
c=fsolve(@(xx)ff(xx,a,b),1);
This will capture a and b in an anonymous function and pass it into ff.

Products

Community Treasure Hunt

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

Start Hunting!