Summation with Hyperbolic Tangent

4 views (last 30 days)
Tony
Tony on 11 Jul 2016
Answered: Walter Roberson on 11 Jul 2016
Hello, I am attempting to perform a summation that utilizes a hyperbolic tangent. A picture is attached of the desired equation. I have tried it with sum(), symsum(), and all sorts of other various ways, but have not had any luck. The most common error is either "Subscript indices must either be real positive integers or logicals." or a different error regarding indexing for symbolic variables. For the symbolic way, I made X the variable, and for normal summation I tried various constant values with no success.

Answers (1)

Walter Roberson
Walter Roberson on 11 Jul 2016
syms x
tF = tanh(100 * (x-1/sym(4)));
F = sum( subs(tF, x, 1:4) );
The result will be tanh(75) + tanh(175) + tanh(275) + tanh(375)
It seems a little odd to sum over your only variable. I would have thought it more likely you would want something like
syms x n
tF = tanh(100 * (x-1/sym(4))^n);
F = sum( subs(tF, n, 1:4) );
which would give
tanh(100*(x - 1/4)^2) + tanh(100*(x - 1/4)^3) + tanh(100*(x - 1/4)^4) + tanh(100*x - 25)

Community Treasure Hunt

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

Start Hunting!