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

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

 Accepted Answer

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 Comments

Thanks... what if I want z(x,y) to equal something other than 0?
Matt J
Matt J on 17 Jan 2016
Edited: Matt J on 17 Jan 2016
If you want z(x,y)=b, then redefine z as z_new(x,y)=z(x,y)-b
Hi Matt... can't seem to get it to work.
If I want z(4,4,constant) = 4, then how can I solve for constant?
Thanks
z = @(x,y,constant) x + y + constant;
x = 4;
y = 4;
const = fzero(@(constant) z(x,y,constant)-4, 1)
This works. Thank you so much!

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Asked:

A
A
on 17 Jan 2016

Commented:

on 22 Jan 2016

Community Treasure Hunt

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

Start Hunting!