Find value of a constant given a value of z(x,y)

1 Ansicht (letzte 30 Tage)
A
A am 17 Jan. 2016
Kommentiert: Star Strider am 22 Jan. 2016
I have the following simplified function:
constant = 5;
z = @(x,y) x + y + constant;
If I want z(4,4) to equal '0', how can I find what value the 'constant' has to be to get me that? I know that I can do a simple arithmetic in the equation above, but what if it's a more complex, multivariate function where it gets really difficult to solve for a variable like that? How can I find the value of 'constant' in that instance?
Thanks

Akzeptierte Antwort

Star Strider
Star Strider am 17 Jan. 2016
Add ‘constant’ to your argument list and use the fzero function is one approach:
z = @(x,y,constant) x + y + constant;
x = 4;
y = 4;
const = fzero(@(constant) z(x,y,constant), 1)
const =
-8
  6 Kommentare
A
A am 22 Jan. 2016
This works. Thank you so much!
Star Strider
Star Strider am 22 Jan. 2016
Our pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by