Finding the root of a function
显示 更早的评论
I'm trying to find x in the following equation using the fzero function.
I'm not sure whether I should use int or integral, and my code doesn't work. Any help?
My code:
N = 100;
S1 = 0;
S2 = 0;
for n = 0:N
S1 = S1 + ((-1)^n/((n + 1/2)*pi)^4*tanh((n + 1/2)*pi*(1+x+x.^2)/2));
S2 = S2 + (1/((n + 1/2)*pi)^5*tanh((n + 1/2)*pi*(1+x+x.^2)/2));
end
cs = 1/2 - 4./(1+x+x.^2).*S1;
cp = 1/3 - 4./(1+x+x.^2).*S2;
syms x
fun = @(x) cs./cp;
q = int(fun,0,x)
gx = @(x) q - 0.0062;
x0 = [0 10];
x = fzero(gx,x0);
The error:
Error using subsindex
Function 'subsindex' is not defined for values of class 'function_handle'.
Error in line 69
q = int(fun,0,x)
2 个评论
Geoff Hayes
2017-12-11
Lilach - please clarify what you mean by your code is not working. Is there an error? If so, please copy and paste the full error message here. Or, are you not getting the expected answer?
Daenerys
2017-12-11
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Descriptive Statistics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!