Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)));
- 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
- t(n+1)=t(n)-f(n).*((t(n+1)-t(n))/(f(n+1)-f(n)));
- 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)= 0.5; %intial guess
- t(2)= 1.5; %intial guess
- Tol=1e-6;
- while tol>Tol
- n=n+1 ;
- tNext = (t(1)*f(t(2)) - t(2)*f(t(1)))/(f(t(2))-f(t(1)));
- t(1) = t(2);
- t(2) = tNext;
- tol=abs(t(2)-t(1));
- disp(['t_',int2str(n),'=',num2str(t(2)),' / f(t_',int2str(n),')=' num2str(f(t(2)))])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement