How can I solve an equation with variables?

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)

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.

2 Comments

Thank you, now it works :)
Please accept this answer then :)

This question is closed.

Products

Asked:

on 8 Sep 2014

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!