Finding Zero of Sum of Functions by Iteration
1 回表示 (過去 30 日間)
古いコメントを表示
I am trying to sum a function and then attempting to find the root of said function. That is, for example, take:
Consider that I have a matrix, X, and vector, t, of values: X(2*n+1,n+1), t(n+1)
for j = 1:n+1
sum = 0;
for i = 1:2*j+1
f = @(g)exp[-exp[X(i,j)+g]*(t(j+1)-t(j))];
sum = sum + f;
end
fzero(sum,0)
end
That is,
I want to evaluate at
j = 1
f = @(g)exp[-exp[X(1,1)+g]*(t(j+1)-t(j))]
fzero(f,0)
j = 2
f = @(g)exp[-exp[X(1,2)+g]*(t(j+1)-t(j))] + exp[-exp[X(2,2)+g]*(t(j+1)-t(j))] + exp[-exp[X(3,2)+g]*(t(j+1)-t(j))]
fzero(f,0)
j = 3
etc...
However, I have no idea how to actually implement this in practice.
Any help is appreciated!
PS - I do not have the symbolic toolbox in Matlab.
0 件のコメント
採用された回答
jgg
2015 年 12 月 22 日
編集済み: jgg
2015 年 12 月 22 日
I think the solution is to write a function:
function [ sum ] = func(j,g,t,X)
sum = 0;
for i = 1:2*j+1
f = exp(-exp(X(i,j)+g)*(t(j+1)-t(j)));
sum = sum + f;
end
end
Then loop your solver
for j=1:n
fun = @(g)func(j,g,t,X);
fzero(fun,0)
end
You'll have to debug the function inside( f = stuff ) (since I don't know what it's supposed to do) so that it returns what you want, but this should solve your problem.
I can get this to solve, but I'm not sure if your f function does what you want it to do.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!