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.

Antworten (1)

Sean de Wolski
Sean de Wolski am 8 Sep. 2014

0 Stimmen

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 Kommentare

Renata Ruskova
Renata Ruskova am 8 Sep. 2014
Thank you, now it works :)
Sean de Wolski
Sean de Wolski am 8 Sep. 2014
Please accept this answer then :)

Diese Frage ist geschlossen.

Produkte

Gefragt:

am 8 Sep. 2014

Geschlossen:

am 20 Aug. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by