Summation of an infinite series - wolfram-mathematica

For the following series,
S= Sum[(e^(a*m*n))*((b^(-m)*(n/2)))),{m,1,infinity}]
I get the output:
By the geometric series test, the series converges.
How to get the actual value of the infinite sum?
Kindly help. Thanks in advance.

Did you actually run the code in Mathematica? You have an extra round bracket. Also infinity is a user variable. Infinity (capital I) is a built in Mathematica symbol:
S = Sum[(e^(a*m*n))*((b^(-m)*(n/2))), {m, 1, Infinity}]
Result:
-((e^(a n) n)/(2 (-b + e^(a n))))
I also suspect that e is the natural exponent. If so, use the capital E.

Related

Why is Mathematica producing a seemingly wrong answer for a derivative?

I'm puzzled by what I think is a mistake in a partial derivative I'm having Mathematica do for me.
Specifically, this is what I have:
Derivative I'd like to take
I'm trying to take the partial derivative of the following w.r.t. the variable θ (apologies for the formatting):
f=(1/4)(-4e((1+θ)/2)ψ+eN((1+θ)/2)ψ+eN((1+θ)/2-θd)ψ)-s
But the solution Mathematica produces seems very different from the one I get when I take the derivative myself. While Mathematica says the partial derivative of f w.r.t. θ is:
(1/4)eψ(N-2)
By hand, I get and am quite confident the correct answer is instead:
(1/4)eψ(N(1-d)-2)
That is, Mathematica is producing something that drops the variable d when it is differentiating. I've explored different functions that take a derivative in Mathematica, and the possibility that maybe some of the variables I'm using (such as d) might be protected or otherwise special, but I can't say that I know why the answer's so off. This is the first time in the notebook that d appears, so it is not set to 0. For context, I'm trying to confirm that the derivative of the function is positive for values of the variables in certain ranges, and we have d>0 and d<(1/2). Doing this all by hand works but I'm trying to confirm with Mathematica as I will be dealing with more complicated functions and need to make sure I'm having Mathematica produce the right derivatives.
Your didn't add spaces in eN and θd, so it thinks they're some other 2-character variables.
Adding spaces between them gives your expected result:
f[θ,e,N,ψ,d,s] = (1/4) (-4 e ((1+θ)/2) ψ + e N ((1+θ)/2) ψ + e N ((1+θ)/2 - θ d) ψ) - s;
D[f[θ, e, N, ψ, d, s], θ] // FullSimplify
(* 1/4 e (-2 + N - d N) ψ *)

Mathematica Does No Find the Global Maximum It Just Print Out My Function

I am am mathmatica notebook to find an analytical solution to the follow constrained optimization problem:
Max y^(1-b)(x^b(1-a(x/(x+1)))) s.t. M = Px+qy
x,y
I have tried the following code:
Maximize[{y^(1-b)(x^b(1-a(x/(x+1)))), M==Px+qy}, {x,y}]
and in returns the same function as an output. In the function a, b, M, P, and q are all parameters. I have also tried assigning the parameters arbitrary values to test to see if mathmatica is not sure how to deal with the parameters. I used to following code:
Maximize[{y^(1-0.5)(x^0.5(1-0.75(x/(x+1)))), 1000=5x+5y},{x,y}]
and it returns the same function. However, if I remove the constraint it will solve the optimization problem.
Maximize[{y^(1-0.5)(x^0.5(1-0.75(x/(x+1))))},{x,y}]
{7.2912*^59,{x->2.89727*^60,y->2.93582*^60}}
I am not sure what to do. After reading about constrained optimization problem the syntax appears to be correct. Sorry, it this question is really basic I am very new to mathmatica, also since I am using a notebook I could not past the output from the first two lines in.
The constraint is incorrectly specified, it should be 1000 == 5 x + 5 y. Maximize works better with exact numbers.
Maximize[{Rationalize[y^(1 - 0.5) (x^0.5 (1 - 0.75 (x/(x + 1))))],
1000 == 5 x + 5 y}, {x, y}] // N
(* {25.7537, {x -> 96.97, y -> 103.03}} *)

Analytic Solution for ODE

I HAVE EQUATION
y - 7(e^x/x)dydx=0
How to find analytic solution in Mathematica?
My work :
I simplify the equations become y'=yx/7e^x
I run in Mathematica,
DSolve[y'[x] == (y[x] x)/(7 e^x), y[x], x]
I get result:
{{y[x] -> E^(1/7 E^-x (-1 - x)) C[1]}}.
Questions:
Are my simplifications correct?
Do I type correct code in step 2?
How to find exact value of C in the result, because I want to use to find y' for given x value
Thank you for the answer

Turbo Prolog: 420 PROLOG.ERR missing

I'm quite new in Prolog. I'm trying to find the nth term and sum of a Fibonacci Series.
/* Fibonacci */
predicates
fibonacci(integer, integer, integer)
clauses
fibonacci(1,1,1):-!.
fibonacci(2,1,2):-!.
fibonacci(N, Term, Sum):-
N1 = N - 1,
N2 = N - 2,
fibonacci(N1, Term1, Sum1),
fibonacci(N2, Term2, Sum2),
Term = Term1 + Term2,
Sum = Term + Sum.
However while compiling in Turbo Prolog I'm getting 420 PROLOG.ERR missing on
fibonacci(N2, Term2, Sum2),
Why is this happening? Any help is appreciated. Thanks in advance.
Is that really the entire error message? It does not say what is missing?
EDIT: According to comments below, Turbo Prolog's = does indeed
correspond to is/2, so the remarks below, which are correct for
Prolog, don't apply. According to comments on the original question,
the terrible error message might be a singleton warning for Sum2.
In any case: Assuming that Turbo Prolog's clauses part corresponds to standard Prolog, none of N1, N2, Term and Sum will be integers in your program. = means unification, not arithmetic evaluation. If you call fibonacci(3, Term, Sum), then inside the call N1 will be bound to the uninterpreted term 3 - 1, not to the integer 2. The same goes for your other uses of =.
For the arithmetic part, you will want to use is/2: N1 is N - 1, N2 is N - 2 etc. This will evaluate the right-hand side as an arithmetic expression and actually bind these variables to integers.
Without thinking about it too hard, it's not clear to me if this will result in a useful computation for Term.
i guessing turbo cant find some file with error descriptions. looks like tp incorrectly installed? correct this and you get more informative message.
look at
http://rosettacode.org/mw/index.php?title=Fibonacci_sequence&action=edit&section=399
and modify it for not only finding Nth but Sum also.
you get something like:
----
% fibsum(i, n, fib(i-2), fib(i-1), fib(i), sum(i-1), sum(i))
fibsum(N, N, Fi2, Fi1, F, Si1, S) :-
F is Fi2 + Fi1,
S is Si1 + F.
fibsum(I, N, Fi2, Fi1, F, Si1, S) :-
In is I + 1,
Fn is Fi2 + Fi1,
Sn is Si1 + Fn, !,
fibsum(In, N, Fi1, Fn, F, Sn, S).
% fibs(i, fib(i), sum(i))
fibs(1, 1, 1).
fibs(2, 1, 2).
fibs(C, N, S) :-
C > 2,
fibsum(3, C, 1, 1, N, 2, S). % Generate from 3rd on
---
(barely tested on http://swish.swi-prolog.org/)
Turbo Prolog cannot find the error messages file PROLOG.ERR. That is normally installed in Turbo Prolog installation directory.
If the file is there, chek that the application path is correctly set under Setup->Directories->Turbo Directory

Problem performing a substitution in a multiple derivative

I have a basic problem in Mathematica which has puzzled me for a while. I want to take the m'th derivative of x*Exp[t*x], then evaluate this at x=0. But the following does not work correct. Please share your thoughts.
D[x*Exp[t*x], {x, m}] /. x -> 0
Also what does the error mean
General::ivar: 0 is not a valid variable.
Edit: my previous example (D[Exp[t*x], {x, m}] /. x -> 0) was trivial. So I made it harder. :)
My question is: how to force it to do the derivative evaluation first, then do substitution.
As pointed out by others, (in general) Mathematica does not know how to take the derivative an arbitrary number of times, even if you specify that number is a positive integer.
This means that the D[expr,{x,m}] command remains unevaluated and then when you set x->0, it's now trying to take the derivative with respect to a constant, which yields the error message.
In general, what you want is the m'th derivative of the function evaluated at zero.
This can be written as
Derivative[m][Function[x,x Exp[t x]]][0]
or
Derivative[m][# Exp[t #]&][0]
You then get the table of coefficients
In[2]:= Table[%, {m, 1, 10}]
Out[2]= {1, 2 t, 3 t^2, 4 t^3, 5 t^4, 6 t^5, 7 t^6, 8 t^7, 9 t^8, 10 t^9}
But a little more thought shows that you really just want the m'th term in the series, so SeriesCoefficient does what you want:
In[3]:= SeriesCoefficient[x*Exp[t*x], {x, 0, m}]
Out[3]= Piecewise[{{t^(-1 + m)/(-1 + m)!, m >= 1}}, 0]
The final output is the general form of the m'th derivative. The PieceWise is not really necessary, since the expression actually holds for all non-negative integers.
Thanks to your update, it's clear what's happening here. Mathematica doesn't actually calculate the derivative; you then replace x with 0, and it ends up looking at this:
D[Exp[t*0],{0,m}]
which obviously is going to run into problems, since 0 isn't a variable.
I'll assume that you want the mth partial derivative of that function w.r.t. x. The t variable suggests that it might be a second independent variable.
It's easy enough to do without Mathematica: D[Exp[t*x], {x, m}] = t^m Exp[t*x]
And if you evaluate the limit as x approaches zero, you get t^m, since lim(Exp[t*x]) = 1. Right?
Update: Let's try it for x*exp(t*x)
the mth partial derivative w.r.t. x is easily had from Wolfram Alpha:
t^(m-1)*exp(t*x)(t*x + m)
So if x = 0 you get m*t^(m-1).
Q.E.D.
Let's see what is happening with a little more detail:
When you write:
D[Sin[x], {x, 1}]
you get an expression in with x in it
Cos[x]
That is because the x in the {x,1} part matches the x in the Sin[x] part, and so Mma understands that you want to make the derivative for that symbol.
But this x, does NOT act as a Block variable for that statement, isolating its meaning from any other x you have in your program, so it enables the chain rule. For example:
In[85]:= z=x^2;
D[Sin[z],{x,1}]
Out[86]= 2 x Cos[x^2]
See? That's perfect! But there is a price.
The price is that the symbols inside the derivative get evaluated as the derivative is taken, and that is spoiling your code.
Of course there are a lot of tricks to get around this. Some have already been mentioned. From my point of view, one clear way to undertand what is happening is:
f[x_] := x*Exp[t*x];
g[y_, m_] := D[f[x], {x, m}] /. x -> y;
{g[p, 2], g[0, 1]}
Out:
{2 E^(p t) t + E^(p t) p t^2, 1}
HTH!

Resources