Hi all,
I am trying to create a function and conditional loop inside,
I was creating this code:
using SymPy, CalculusWithJulia
@vars k n
function specialsum(k)
if k = i
k = (n*(n+1))/2
elseif k = i^2
k = (n*(n+1)*(2n+1))/6
elseif k = i^3
k = ((n(n+1))/2)^2
elseif k = i^4
k = (n*(n+1)*(2n+1)*(3n^2 + 3n - 1))/30
else
k = k
end
return
end
x = 7i
println("The sum for $x is:")
k = specialsum(x)
Error occured:
WARNING: Method definition (::Type{Base.Order.Lt{T} where T})(Function, Real) in module ImplicitEquations at /home/browni/.julia/packages/ImplicitEquations/YhI8o/src/predicates.jl:55 overwritten in module CalculusWithJulia at /home/browni/.julia/packages/CalculusWithJulia/Z8IBs/src/plot-utils.jl:16.
** ** incremental compilation may be fatally broken for this module ****
ERROR: LoadError: syntax: unexpected â=â
Stacktrace:
** [1] top-level scope**
** @ ~/LasthrimProjection/plot.jl:5**
** [2] include(fname::String)**
** @ Base.MainInclude ./client.jl:451**
** [3] top-level scope**
** @ REPL[1]:1**
in expression starting at /home/browni/LasthrimProjection/plot.jl:5
The idea is when I put x=7i
or x=$i^2$
then it should print the special sum formula in n
terms.
Like this screenshot
Thus,
i = n(n+1)/2 and so on