Advertisement
BORUTO-121

kosi_hitac(4)

Mar 8th, 2022
187
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [a,b]=zad1(17.5,0.01,20,1);
  2.  
  3. function [v0,alpha]=zad1(xfinal,odstupanje,vmax,crtanje)
  4.     %%Check for number of arguments min. value =1
  5.     if(nargin==0)
  6.         fprintf("Zadatak nije moguce rijesiti\n");
  7.         return;
  8.     end
  9.    
  10.     %%Gravitational acceleartion
  11.     g=9.81;
  12.     %%Search: fix speed, change angle alpha from pi/4 and divide the
  13.     %%interval to half parts
  14.    
  15.     %%First check if possible (we'll  take vmax and angle for max distance)
  16.    
  17.     if(xfinal-vmax*vmax/g>odstupanje)
  18.         fprintf("Zadatak nije moguce rijesiti");
  19.         return;
  20.     end
  21.     %%Optimal launch angle for max. distance is alpha=pi/4
  22.     alpha=pi/4;
  23.    
  24.     vdonja=0;
  25.     vsredina=vmax/2.;
  26.     v0=vsredina;
  27.     while abs(xfinal-v0*v0/g)>odstupanje
  28.         if xfinal-v0*v0/g<0
  29.             %Polovimo interval 0 - vgranica (prebacaj) smanji
  30.             v0=(vsredina+vdonja)/2.;
  31.             vmax=vsredina;
  32.             vsredina=v0;
  33.         else
  34.             v0=(vsredina+vmax)/2.;
  35.             vdonja=vsredina;
  36.             vsredina=v0;
  37.         end
  38.     end
  39.     if crtanje==1
  40.         x=0:0.01:xfinal;
  41.         y=x.*tan(alpha)-g*x.^2/(2*v0^2*(cos(alpha)^2));
  42.         plot(x,y,'r');
  43.         hold on;
  44.         plot(xfinal,0,'*k');
  45.     end
  46. end
Advertisement
RAW Paste Data Copied
Advertisement