От: | Marty | https://www.youtube.com/channel/UChp5PpQ6T4-93HbNF-8vSYg | |
Дата: | 27.01.19 13:06 | ||
Оценка: |
От: | kov_serg | ||
Дата: | 27.01.19 14:55 | ||
Оценка: |
#include <math.h>
struct tetrahedron {
double a,b,c,ea,eb,ec;
double volume() const {
double A=a*a, B=b*b, C=c*c, X=B+C-ea*ea, Y=A+C-eb*eb, Z=A+B-ec*ec;
return sqrt(4*A*B*C-A*X*X-B*Y*Y-C*Z*Z+X*Y*Z)/12;
}
};
#include <stdio.h>
int main(int argc,char** argv) {
tetrahedron t;
t.a=1; t.b=1; t.c=1;
t.ea=1; t.eb=1; t.ec=1;
double V=t.volume(), V0=sqrt(2)/12;
printf("V=%.5f (%.5f)\n",V,V0);
return 0;
}
От: | Marty | https://www.youtube.com/channel/UChp5PpQ6T4-93HbNF-8vSYg | |
Дата: | 27.01.19 21:26 | ||
Оценка: |
_>#include <math.h>
_>struct tetrahedron {
_> double a,b,c,ea,eb,ec;
_> double volume() const {
_> double A=a*a, B=b*b, C=c*c, X=B+C-ea*ea, Y=A+C-eb*eb, Z=A+B-ec*ec;
_> return sqrt(4*A*B*C-A*X*X-B*Y*Y-C*Z*Z+X*Y*Z)/12;
_> }
_>};
_>#include <stdio.h>
_>int main(int argc,char** argv) {
_> tetrahedron t;
_> t.a=1; t.b=1; t.c=1;
_> t.ea=1; t.eb=1; t.ec=1;
_> double V=t.volume(), V0=sqrt(2)/12;
_> printf("V=%.5f (%.5f)\n",V,V0);
_> return 0;
_>}
_>
От: | kov_serg | ||
Дата: | 27.01.19 22:12 | ||
Оценка: |
_>>for(val=0;(digit=L::dec(*p))>=0;p++){
_>> t=val*10+digit;
_>> if (t<val && t!=-t) return defval; // overflow
_>> val=t;
_>>}
_>> tetrahedron t;
_>> t.a=1; t.b=1; t.c=1;
_>> t.ea=1; t.eb=1; t.ec=1;
_>> double V=t.volume();
От: | Marty | https://www.youtube.com/channel/UChp5PpQ6T4-93HbNF-8vSYg | |
Дата: | 29.01.19 18:08 | ||
Оценка: |
От: | kov_serg | ||
Дата: | 29.01.19 20:33 | ||
Оценка: |
Насладитесь прекрасным: | |
https://www.youtube.com/watch?v=N9uSr-8FJ2M&t=182 | |
subroutine quart(n,c,r4,jj,mm)
c use the procedure of la-4299 to solve the quartic equation
c x**4+b*x**3+c*x**2+d*x+e=0 (c(i),i=1,5)=1,b,c,d,e
c the jj real roots are returned in r4. the roots with odd
c multiplicity are listed first, in ascending order. if mm=0,
c the roots with even multiplicity are omitted.
implicit double precision (a-h,o-z)
dimension c(5),r4(4),tp(16)
parameter (pf=(2.*3.1415926535898d0)/3.,th=1d0/3.)
c
jj=0
if(n.eq.3)go to 90
c
c let y=x+b/4 to reduce the quartic equation to
c y**4+q*y**2+r*y+s=0 (tp(i),i=1,5)=b/2,b/4,q,r,s
tp(1)=.5*c(2)
tp(2)=.25*c(2)
tp(3)=c(3)-1.5*tp(1)**2
tp(4)=c(4)+tp(1)*(tp(1)**2-c(3))
tp(5)=c(5)-.0625*tp(1)*(5.*c(4)-c(3)*tp(1)+3.*tp(4))
c
c steps 2-7 (la-4299) (tp(i),i=6,11)=b/3,c,d,p/3,q/2,w
if(abs(tp(4)).le.1.e-10*max(abs(c(4)),tp(1)**2,abs(tp(1)*c(3))))
1 go to 40
tp(6)=2.*th*tp(3)
tp(7)=tp(3)**2-4.*tp(5)
tp(8)=-tp(4)**2
tp(9)=th*tp(7)-tp(6)**2
tp(10)=.5*(tp(8)-tp(6)*(tp(7)-2.*tp(6)**2))
tp(11)=tp(9)**3+tp(10)**2
if(abs(tp(11)).le.1.e-10*max(abs(tp(9)**3),tp(10)**2))go to 10
if(tp(11).gt.0.)go to 30
tp(12)=sqrt(-tp(9))
if(tp(6).ge.0..or.tp(7).le.0.)return
tp(13)=-tp(10)/tp(12)**3
if(abs(tp(13)).ge.1.)go to 10
tp(13)=acos(tp(13))
tp(14)=2.*tp(12)*cos(th*tp(13))-tp(6)
if(tp(14).lt.1.e-10*abs(tp(6)))go to 40
tp(15)=.5*sqrt(tp(14))
tp(14)=-tp(14)-3.*tp(6)
tp(16)=tp(4)/tp(15)
if(abs(tp(16)).ge.tp(14))go to 10
jj=4
tp(13)=.5*sqrt(tp(14)+tp(16))
r4(1)=-tp(13)-tp(15)-tp(2)
r4(2)=tp(13)-tp(15)-tp(2)
tp(13)=.5*sqrt(tp(14)-tp(16))
r4(3)=tp(15)-tp(13)-tp(2)
r4(4)=tp(15)+tp(13)-tp(2)
return
c
c steps 8-11 (la-4299) double or triple roots.
10 tp(12)=sign(sqrt(abs(tp(9))),tp(10))
tp(13)=-2.*tp(12)-tp(6)
tp(14)=tp(12)-tp(6)
tp(15)=sign(.5*sqrt(abs(tp(13))),tp(4))
if(tp(14).le.0.)go to 20
tp(16)=sqrt(tp(14))
jj=2
r4(1)=-tp(15)-tp(2)-tp(16)
r4(2)=tp(16)-tp(15)-tp(2)
if(mm.eq.0)return
if(tp(10).eq.0.)return
jj=3
r4(3)=tp(15)-tp(2)
return
20 if(mm.eq.0)return
jj=1
r4(1)=-tp(15)-tp(2)
return
c
c step 12 (la-4299)
30 tp(12)=-tp(10)-sign(sqrt(tp(11)),tp(10))
tp(12)=sign(abs(tp(12))**th,tp(12))
tp(14)=tp(12)-tp(9)/tp(12)-tp(6)
if(tp(14).lt.1.e-10*abs(tp(6)))go to 40
tp(15)=.5*sign(sqrt(tp(14)),tp(4))
tp(16)=abs(tp(4)/tp(15))-tp(14)-3.*tp(6)
if(tp(16).le.0.)return
tp(16)=.5*sqrt(tp(16))
jj=2
r4(1)=-tp(16)-tp(15)-tp(2)
r4(2)=tp(16)-tp(15)-tp(2)
return
c
c steps 13-24 (la-4299) trivial case; r=tp(4)=0
40 tp(6)=.5*tp(3)
tp(7)=tp(6)**2-tp(5)
tp(9)=1.e-8*max(tp(6)**2,abs(tp(5)))
if(tp(7).le.tp(9))go to 60
tp(8)=sqrt(tp(7))
tp(16)=tp(8)-tp(6)
if(tp(16).le.0.)go to 70
tp(15)=-tp(6)-tp(8)
tp(16)=sqrt(tp(16))
if(tp(15).gt.0.)go to 50
jj=2
r4(1)=-tp(16)-tp(2)
r4(2)=tp(16)-tp(2)
if(mm.eq.0)return
if(tp(15).ne.0.)return
jj=3
r4(3)=-tp(2)
return
50 tp(15)=sqrt(tp(15))
jj=4
r4(1)=-tp(16)-tp(2)
r4(2)=-tp(15)-tp(2)
r4(3)=tp(15)-tp(2)
r4(4)=tp(16)-tp(2)
return
60 if(mm.eq.0)return
if(tp(7).lt.-tp(9).or.tp(6).gt.0.)return
if(tp(6).eq.0.)go to 80
jj=2
tp(16)=sqrt(-tp(6))
r4(1)=tp(16)-tp(2)
r4(2)=-tp(16)-tp(2)
return
70 if(mm.eq.0)return
if(tp(16).lt.0.)return
80 jj=1
r4(1)=-tp(2)
return
c
c cubic equation. x**3+b*x**2+c*x+d=0 (c(i),i=1,4)=1,b,c,d
c let y=x+b/3. then y**3+p*y+q=0 (tp(i),i=1,4)=b/3,p/3,q/2,w
90 tp(1)=th*c(2)
tp(2)=th*c(3)-tp(1)**2
tp(3)=.5*(c(4)-tp(1)*(c(3)-2.*tp(1)**2))
tp(4)=tp(2)**3+tp(3)**2
if(tp(4).gt.0.)go to 110
if(tp(4).eq.0.)go to 100
c
c case i (la-4299) 3 distinct roots
tp(5)=2.*sqrt(-tp(2))
tp(6)=8.*tp(3)/tp(5)**3
if(abs(tp(6)).ge.1.)go to 100
tp(7)=th*acos(-tp(6))
r4(1)=tp(5)*cos(pf+tp(7))-tp(1)
r4(2)=tp(5)*cos(pf-tp(7))-tp(1)
r4(3)=tp(5)*cos(tp(7))-tp(1)
jj=3
return
c
c case ii (la-4299) 1 distinct and 1 double root
100 r4(1)=-2.*sign(sqrt(-tp(2)),tp(3))-tp(1)
jj=1
if(mm.eq.0)return
if(r4(1).eq.0.)return
jj=2
r4(2)=-.5*r4(1)
return
c
c case iii (la-4299) 1 distinct root
110 tp(5)=-tp(3)-sign(sqrt(tp(4)),tp(3))
tp(5)=sign(abs(tp(5))**th,tp(5))
r4(1)=tp(5)-tp(2)/tp(5)-tp(1)
jj=1
return
end