inline function error help(tanh)

1 Ansicht (letzte 30 Tage)
Nathan latchman
Nathan latchman am 20 Apr. 2019
Kommentiert: Nathan latchman am 20 Apr. 2019
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)');

Antworten (1)

David Wilson
David Wilson am 20 Apr. 2019
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 Kommentar
Nathan latchman
Nathan latchman am 20 Apr. 2019
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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Function Creation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by