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

조회 수: 1 (최근 30일)
A
A 2016년 1월 17일
댓글: Star Strider 2016년 1월 22일
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

채택된 답변

Star Strider
Star Strider 2016년 1월 17일
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
A
A 2016년 1월 22일
This works. Thank you so much!
Star Strider
Star Strider 2016년 1월 22일
Our pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by