Advertisement
gasaichan

Untitled

May 21st, 2017
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.89 KB | None | 0 0
  1. function[n]  =  Lab5_1( f,X0,A,n0,e )
  2. % f - функция с символьными х,у
  3. % Х0 - координаты начальной точки
  4. % А - отрезок [a,b]
  5. % n0 - начальное число отрезкой разбиения
  6. % е - точность
  7.  
  8.  
  9. % Starting Point
  10. x0=X0(1);
  11. y0=X0(2);
  12.  
  13. % Interval
  14. a=A(1);
  15. b=A(2);
  16.  
  17.  
  18. dx=(b-a)/n0;
  19.  
  20. % X and Y arrays for plot
  21. X(1)=x0;
  22. Y(1)=y0;
  23.  
  24. % X1 and Y1 arrays for n*2 plot
  25. X1(1) = x0;
  26. Y1(1) = y0;
  27.  
  28. for i=1:1:n0
  29. syms x y;
  30. if (Y(i) + subs(f,{'x','y'},[X(i) Y(i)])*dx == inf)
  31.     break
  32. else
  33.     Y(i+1) = Y(i) + subs(f,{'x','y'},[X(i) Y(i)])*dx;
  34. end
  35. X(i+1) = X(i) + dx;
  36. end
  37. plot(X, Y, 'r')
  38. dx = dx/2;
  39. n = n0*2;
  40. for i=1:1:2*n0
  41. if (Y1(i) + subs(f,{'x','y'},[X1(i) Y1(i)])*dx == inf)
  42.     break
  43. else
  44.     Y1(i+1) = Y1(i) + subs(f,{'x','y'},[X1(i) Y1(i)])*dx;
  45. end
  46. X1(i+1) = X1(i) + dx;
  47. plot(X1,Y1,'g');
  48. end
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement