Finding Zero of Sum of Functions by Iteration
16 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
jgg
on 22 Dec 2015
Edited: jgg
on 22 Dec 2015
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 Comment
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!