How to find the input to a function given the result?

1 回表示 (過去 30 日間)
Alejandro Morales
Alejandro Morales 2014 年 11 月 23 日
コメント済み: Star Strider 2014 年 11 月 23 日
Hello
I have a function called RKS which accepts 2 values T and P and gives me a value S. In the main script it looks like this:
S=RKS(T,P);
If I have S and P and I am trying to find T how can I do it using the matlab solver. I was told that I could do it this way without having to modify the RKS function itself but I have not study how to use the solver in matlab and can't figure it out. I keep getting errors. Also if there is any other way of getting T I am open to subjection.
Thanks You.

回答 (1 件)

Star Strider
Star Strider 2014 年 11 月 23 日
Here is one possibility:
RKS = @(T,P) P.^-T;
P = 5;
S = RKS(3,P);
T = fzero(@(T) RKS(T,P)-S, 1);
  2 件のコメント
Alejandro Morales
Alejandro Morales 2014 年 11 月 23 日
What is the 3 in
S = RKS(3,P);
suppose to be? A random guess?.
Star Strider
Star Strider 2014 年 11 月 23 日
Yes.
Both the ‘3’ and the ‘RKS’ function are random guesses. The point is to illustrate an approach to recovering ‘T’.
This assumes that the function S(P,T) is one-to-one. If the function is a power of ‘T’, periodic in ‘T’, or something else, the solution would not necessarily be unique.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by