• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Mar 14th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. clear
2. xdel(winsid());
3.
4. x0 = 0;
5. y0 = 1;
6. xe = 2;
7. ye = 2;
8.
9. Nx = 5;
10. x = linspace(x0,xe,Nx)';
11. dx = x(2)-x(1);
12.
13. function wyn = fa(x)
14.     wyn = -sqrt(5)*x/6 + sqrt(1 + x.^2)/3 + (2+x.^2)/3;
15. endfunction
16.
17. function wyn = f1(x)  // elements of the main diagonal
18.      wyn = 4*(1+x.^2)+2*dx^2;
19. endfunction
20.
21. function wyn = f2(x) // elements of the upper diagonal
22.      wyn = 2*(1+x.^2)+x*dx;
23. endfunction
24.
25. function wyn = f3(x) // elements of the lower diagonal
26.      wyn = 2*(1+x.^2)-x*dx;
27. endfunction
28.
29. function wyn = f4(x)   //elements of the right han d side vector
30.      wyn = 2*x.^2*dx^2;
31. endfunction
32.
33. A = diag(-f1(x(2:\$-1))) + diag(f2(x(2:\$-2)), 1) + diag(f3(x(3:\$-1)),-1);
34.
35. b = f4(x(2:\$-1));
36. b(1) = b(1) - f3(x(2))*y0;
37. b(\$) = b(\$) - f2(x(\$-1))*ye;
38.
39. y = A\b;
40. y=[y0;y;ye];
41.
42. ya = fa(x);
43. scf();
44.
45. plot2d(x,y,style=5)
46. plot2d(x,ya,style=2)
47. xtitle(msprintf("Numerical and analytical aolutions, %d division",Nx));
48. legend(['numerical','analytical'],2,%f);
49.
50. scf();
51. plot2d(x,y-ya,style=5)
52. xtitle(msprintf("Absolute errors, %g divisions",Nx));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top