inline function error help(tanh)

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Function Creation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by