Why when I assign x(n)=0.5 and x(n-1)=0.055 they are gathered into one vector? as x=[0.5 0.055]
1 view (last 30 days)
Show older comments
Khalil Ishaq
on 31 Oct 2016
Commented: Walter Roberson
on 1 Nov 2016
I am doing a code for Newton-Raphson using Secant method as well. However, I should guess two values! How can I do that? you can see the attachment for my code. Please help if you can.
2 Comments
Accepted Answer
Walter Roberson
on 31 Oct 2016
You might as well use rand() for the initial guesses, unless you have physical knowledge that would suggest other values.
You are going to need to change your code. You have
f(x(n))=((-(100-DOT(i)))/(100))+(1/(x(n)-60))*(x(n)*exp(-Time(i)/x1)-60*exp(-Time(i)/60))
for i=1:43
while abs((f(x1)))>0.001
x(n+1)=x(n)-((x(n)-x(n-1)))*(f(x(n))/(f(x(n))-f(x(n-1))))
x0=x1;
x1=x2;
n=n+1;
end
end
which tries to define a formula for f(x(n)) based upon general n and i values. The only way to define a formula is with the Symbolic Toolbox, and symbolic formulas need to be define in terms of variables rather than array elements.
Adjusted code:
x1 = nan; %we do not know what this variable is for or how it should be initialized
x2 = nan; %we do not know what this variable is for or how it should be initialized
for i=1:43
f = @(X, X1) ((-(100-DOT(i)))/(100))+(1/(X-60))*(X*exp(-Time(i)/X1)-60*exp(-Time(i)/60));
while abs((f(x(n), x1)))>0.001
x(n+1) = x(n)-((x(n) - x(n-1))) * (f(x(n), x1) / (f(x(n),x1) - f(x(n-1),x1)));
x0=x1;
x1=x2;
n=n+1;
end
end
This adjusted code is unlikely to work, as I see errors in your formula, but it will at least pass syntax checking.
2 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!