Finding Zero of Sum of Functions by Iteration

조회 수: 17 (최근 30일)
Gregory McArthur
Gregory McArthur 2015년 12월 22일
편집: Gregory McArthur 2015년 12월 22일
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에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by