Attempted to access t(3); index out of bounds because numel(t)=2. Error in Project_1c (line 17) t(n+1)=t(n)-f(n).*((t(n+1)-t(n))/(f(n+1)-f(n)));
1 view (last 30 days)
Show older comments
clc;
clear all;
close all;
f=@(t)(sin((pi)*t).*exp(-t));
t1=linspace(-1,5,100);
f1=f(t1);
plot(t1,f1)
n= 1; %index start
tol= 100; %convergence tolerance
t(1)= -1; %intial guess
t(2)= 0; %intial guess
Tol=1e-6;
while tol>Tol
n=n+1
t(n+1)=t(n)-f(n).*((t(n+1)-t(n))/(f(n+1)-f(n)));
f(n+1)=f(t(n+1))
tol=abs(t(n+1)-t(n))
end
0 Comments
Answers (1)
Walter Roberson
on 27 Aug 2015
t(n+1)=t(n)-f(n).*((t(n+1)-t(n))/(f(n+1)-f(n))) defines t(n+1) in terms of t(n+1) which does not exist yet.
If the expression is intended to be a recurrence formula, then you will find that it is satisfied for t(n) being constant, for all non-zero (f(n)-f(n+1)) .
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!