inline function error help(tanh)

1 回表示 (過去 30 日間)
Nathan latchman
Nathan latchman 2019 年 4 月 20 日
コメント済み: Nathan latchman 2019 年 4 月 20 日
hi,
can anyone help with writing an inline function using tanh, e.g:
fx = inline('((2.*pi^2)./t)-((g*2*pi)./x).*tanh((2*pi*h)./x)');

回答 (1 件)

David Wilson
David Wilson 2019 年 4 月 20 日
I can, but perhaps you should use anonymous functions. The inline approach is now discouraged.
Instead of what you wrote above, try:
fx2 = @(g,h,t,x) ((2.*pi^2)./t)-((g*2*pi)./x).*tanh((2*pi*h)./x)
g= 1;h=2;t=3;
x = linspace(0,5)';
plot(x, fx2(g,h,t,x))
However going by your chouce of variable names, I'm assuming that g,h, & t are constants, and that x is the variable. In that case try:
g= 1;h=2;t=3; % fold constants in the definition
fx3 = @(x) ((2.*pi^2)./t)-((g*2*pi)./x).*tanh((2*pi*h)./x)
x = linspace(0,5)';
plot(x, fx3(x))
Is this what you want? Of course f(x=0) returns -inf (for my values of h etc).
  1 件のコメント
Nathan latchman
Nathan latchman 2019 年 4 月 20 日
thank you David. h and are constants here but i was just using those two to get the program to run i will have to change them to varibles. later on.
I'm trying to make a program to solve false position for that function

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

カテゴリ

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