inline function error help(tanh)

2 visualizaciones (últimos 30 días)
Nathan latchman
Nathan latchman el 20 de Abr. de 2019
Comentada: Nathan latchman el 20 de Abr. de 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)');

Respuestas (1)

David Wilson
David Wilson el 20 de Abr. de 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 comentario
Nathan latchman
Nathan latchman el 20 de Abr. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre Function Creation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by