Advertisement
Guest User

Untitled

a guest
Aug 27th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. Attempted to access t(3); index out of bounds because numel(t)=2.
  2.  
  3. Error in Project_1c (line 17)
  4. t(n+1)=t(n)-f(n).*((t(n+1)-t(n))/(f(n+1)-f(n)));
  5.  
  6. clc;
  7. clear all;
  8. close all;
  9.  
  10. f=@(t)(sin((pi)*t).*exp(-t));
  11. t1=linspace(-1,5,100);
  12. f1=f(t1);
  13. plot(t1,f1)
  14.  
  15. n= 1; %index start
  16. tol= 100; %convergence tolerance
  17. t(1)= -1; %intial guess
  18. t(2)= 0; %intial guess
  19. Tol=1e-6;
  20. while tol>Tol
  21. n=n+1
  22. t(n+1)=t(n)-f(n).*((t(n+1)-t(n))/(f(n+1)-f(n)));
  23. f(n+1)=f(t(n+1))
  24. tol=abs(t(n+1)-t(n))
  25. end
  26.  
  27. t(n+1)=t(n)-f(n).*((t(n+1)-t(n))/(f(n+1)-f(n)));
  28.  
  29. clc;
  30. clear all;
  31. close all;
  32. f=@(t)(sin((pi)*t).*exp(-t));
  33. t1=linspace(-1,5,100);
  34. f1=f(t1);
  35. plot(t1,f1)
  36.  
  37. n= 1; %index start
  38. tol= 100; %convergence tolerance
  39. t(1)= 0.5; %intial guess
  40. t(2)= 1.5; %intial guess
  41. Tol=1e-6;
  42. while tol>Tol
  43. n=n+1 ;
  44. tNext = (t(1)*f(t(2)) - t(2)*f(t(1)))/(f(t(2))-f(t(1)));
  45. t(1) = t(2);
  46. t(2) = tNext;
  47. tol=abs(t(2)-t(1));
  48. disp(['t_',int2str(n),'=',num2str(t(2)),' / f(t_',int2str(n),')=' num2str(f(t(2)))])
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement