A function finds a value x from values (a, b, c).
How can I find the input c, given that I know the inputs a, b and the output x?

 採用された回答

Star Strider
Star Strider 2020 年 3 月 4 日

0 投票

One approach:
fabc = f(a,b,c); % Value Of Function Evaluated With All Arguments
find_c = fsolve(@(c)norm(fabc - f(a,b,c)), rand); % Find Unknown Argument
However it depends on what ‘A function’ is, since if it has several roots, the unknown parameter may not be uniquely identifiable.

4 件のコメント

Elouise Matthews
Elouise Matthews 2020 年 3 月 4 日
Thank you so much for your help!
This method appears to work for me.
Good to know that this would not work if I had had roots in the function.
Star Strider
Star Strider 2020 年 3 月 4 日
My pleasure!
It creates a root by subtracting the know value from the funciton, so that fsolve can find the value of the parameter at the equality. If there are more than one root, it would be appropriate to test it in the region of each one.
If my Answer helped you solve your problem, please Accept it!
Ravikiran Nataraj
Ravikiran Nataraj 2021 年 9 月 27 日
Hey guys,
I'm having trouble understanding this solution and why it works. I understand why fabc = f(a, b, c); is needed to create a value for an output based on given inputs. However, why is fabc - f(a,b,c) in the 2nd line. Isn't that value 0? What is purpose of using norm & rand?
I'm facing a similar problem but 'fsolve' returns the initial guess (you used rand) because it says the difference in arguments is 0. Here's my code.
diff = find_Z(dataT(1), dataT(2), dataP(1), dataP(2), w);
fopt = find_Z(dataT(1), dataT(2), dataP(1), dataP(2), w) - diff;
T_vle = fsolve(@(T) fopt, 270)
I have a function 'find_Z' w/ 5 inputs and 5 outputs (I've chosen to store ONLY the first output). I'm trying to optimize output arg 1 'diff' to 0 by changing input arg 1 (T). But when I solve it, fopt is equal to 0 and fsolve returns 270, my initial guess.
How can I fix this & better understand how 'fsolve' works?
Star Strider
Star Strider 2021 年 9 月 27 日
@Ravikiran Nataraj — This is an abstract solution to an abstract problem, and it may not apply to the situation you pose. If you have a specific problem, post it as a new Question.

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

その他の回答 (1 件)

abdulaziz allohani
abdulaziz allohani 2021 年 2 月 25 日

0 投票

>>x=[2 5 6 8 9 6]

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by