inline function with 3 variables

9 ビュー (過去 30 日間)
Nathan latchman
Nathan latchman 2019 年 4 月 20 日
コメント済み: Nathan latchman 2019 年 4 月 20 日
hello,
I'm trying to run this code but I don;t know how to write the function in a way that uses the values of h and t, then fx(a) and fx(b). can anyone please help
t = [5 6 7 8 9]
h= [2 3 4 5 6]
fx =inline('((2*pi.^2)./t)-(((9.81*2*pi)./x).*tanh((2*pi*h)./x))')
a = 1;
b = 10;
tol = 0.001;
fx(a)
fx(b)

採用された回答

Walter Roberson
Walter Roberson 2019 年 4 月 20 日
You cannot do that with inline functions. Every name you mention in an inline function must either be a function call (like tanh or pi -- pi is a function), or else it is turned into a parameter that must be passed to the function at the time it is executed.
You should not use inline functions unless someone imposes a requirement on you that you cannot overrule. You should use anonymous functions instead. http://www.mathworks.com/help/matlab/math/parameterizing-functions.html
  1 件のコメント
Nathan latchman
Nathan latchman 2019 年 4 月 20 日
thank you. I ended up using anonymous function and that worked. only problem is now the function keeps running for much longer than i think it should so, some progress made and some to go.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by