inline function error help(tanh)

2 visualizzazioni (ultimi 30 giorni)
Nathan latchman
Nathan latchman il 20 Apr 2019
Commentato: Nathan latchman il 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)');

Risposte (1)

David Wilson
David Wilson il 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 Commento
Nathan latchman
Nathan latchman il 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

Accedi per commentare.

Categorie

Scopri di più su Function Creation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by