Finding Zero of Sum of Functions by Iteration

4 次查看(过去 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.

采纳的回答

jgg
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.
  1 个评论
Gregory McArthur
Gregory McArthur 2015-12-22
编辑:Gregory McArthur 2015-12-22
This is really impressive, actually, and probably what I would do if I was better at MATLAB.
Thanks!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by