Mahathi Vempati
Mahathi Vempati

Reputation: 1378

How to fix components of solution vector in fsolve?

Say I have a function as follows:

function f = fun(a,b,c)
    f = a + b + c
end

Now I want to do find the solution as follows:

function f = find_a(b,c)
    f = fsolve(@fun, [0,b,c])
end

However, I’d like to keep b and c fixed, find only a solution for a. How can I accomplish this?

Upvotes: 0

Views: 42

Answers (1)

Cris Luengo
Cris Luengo

Reputation: 60444

You can create an anonymous function with one input that calls fun with the fixed values of b and c:

function f = find_a(b,c)
  f = fsolve(@(a)fun(a,b,c), 0)
end

Upvotes: 2

Related Questions