Error when using symsum in function declaration
显示 更早的评论
I apologize for any obvious errors, this is my first time ever using Matlab, and I'm struggling a bit to get used to the syntax. I have defined 3 functions:
function fact = fact2(n)
if n == 0
fact = 1;
elseif n == -1
fact = 1;
elseif mod(n,2) == 0
fact = prod(2:2:n);
elseif mod(int8(n),2) == 1
fact = prod(1:2:n);
end
Note: this function is apparently a built-in function, but when I try to use it, it says it's not defined. I assume that I am missing some package, but have no idea how to go about fixing that, so I wrote it myself. The function is a double factorial.
function sumArgument = asymArgErf(n)
sumArgument = (-1)^n * fact2(2*n-3) / (8^n-1);
end
function Asymptotic = erf2Asym(n)
syms k;
Asymptotic = 1 + (exp(-4)/(2*sqrt(pi))) * symsum(asymArgErf(k), k, 1, n);
end
The first two functions run just fine in my command window, however the third gives me an error
Error using : (line 38)
Unable to compute number of steps from 1 to 2*k - 3 by 2.
Error in fact2 (line 9)
fact = prod(1:2:n);
Error in asymArgErf (line 2)
argument2 = (-1)^n * fact2(2*n-3) / (8^n-1);
Error in erf2Asym (line 3)
Asymptotic = 1 + (exp(-4)/(2*sqrt(pi))) * symsum(asymArgErf(k), k, 1, n);
This seemed like the function was having problems with me inputting what I'm guessing is a symbol type variable into asymArgErf(k). However when I tried converting the type, I got even longer error messages. Could somebody help me resolve this?
_____________________________________________________________________________
I also tried a simpler case directly into my command window and got an error:
>> syms k
>> symsym(fact2(k), k, 1, 3)
Output argument "fact" (and maybe others) not assigned during call to "fact2".
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Mathematics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!