Advertisement
Guest User

Untitled

a guest
May 15th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.80 KB | None | 0 0
  1. Q = 1.2;
  2. g = 9.81;
  3. b = 1.8;
  4. h0 = 6;
  5. H = 0.075;
  6. c0 = 1;
  7. c1 = H - h0 -(Q .^ 2 / (2 * g * (b * h0).^2))
  8. c2 = 0
  9. c3 = (Q .^2 /(2 * g * b .^ 2)
  10. %f(x) - the function of the polynomil
  11. f=@(x) c0 * x .^ 3 + c1 * x .^ 2 + c3;
  12. %function to find the derivative of the polynomial
  13. function d = derivative(x)
  14.     h = 0.000001;
  15.     d = (f(x + h) - f(x)) / h
  16.  
  17. newton_raphson = @(x) x - (f(x) / derivative(x))
  18.  
  19. funcion x = iterate(p, n)
  20.     x = p;
  21.     for i in 1:n
  22.         x = newton_raphson(x)
  23.     end
  24. fprintf('Approximate head is %.15f',x)
  25. end
  26. iterate(80, 100)  
  27.  
  28. %{ another solution:
  29. p = [c0 c1 c2 c3];
  30. r = roots(p);
  31. h = r(1);
  32. fprintf('Approximate head is %.15f',h)
  33. %}
  34.  
  35.  
  36. x = 0:0.1:10;
  37. plot(x,f(x))
  38. ylim([-10 10])
  39. xlabel('The head over pump')
  40. ylabel('Bernoulli equation')
  41. grid on
  42. hold on
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement