Tak co stim mam delat......?????
Příspěvky odeslané z IP adresy 88.103.192.–
Dobrý den,
Našel jsem Vaše stránky o programování.
Potřeboval bych upravit program. Jednalo by se o zmenu nazvu vstupních veličin a přepsaní vzorce na výpočet hodnot. Program který to vyhodnocuje se jmenuje Rgui. Upravovaný program je na výpočet efektivity koutoveho svaru a ja navrhuji tupý svar je to do mé DP. Mužete se na to podívat zda to dokažete upravit. Děkuji Myšák. Byl by někdo tak hodný a pomohl by mi s úpravou... Vzorce mohu taky dodat
kontakt: ondrej.mysak@seznam.cz
Upravovany program je :
#zadej k, implicitn� je 1.04
#zadej U, vd,vs, v, z
analyza<-function(file="c:\\Opt2.txt",nap=-1,vrs=15,poc=1,kon=-1,pocet=100,kof=1.04)
{
library(grDevices)
library(lattice)
options(warn=-5)
p<-as.integer(readline("zadej po�et parametr� "))
############
if(p==3) {
data<-matrix(scan(file), byrow=T, ncol=5)
if(kon<0) kon<-length(data[,1])
data<-data[poc:kon,]
U<-data[,1]
vd<-data[,2]
vs<-data[,3]
v<-data[,4]
z<-data[,5]
n<-length(vd)
Ps<-kof*vd/vs
vt<-1:n
for (i in 1:n) vt[i]<-uniroot(funHu, low = -1000, up = 1000, tol = 0.01, a=Ps[i], b=z[i])$root
Ef<-z/vt*(v-z)/(vt-z)
rozsah<-matrix(0,4,4)
x1<-U
x2<-vd
x3<-Ps
odp<-readline("Chce� nastavit rozsahy veli�in (stiskni a v p��pad� ano) ")
if(odp=="a") {
rozsah[1,1]<-as.real(readline("Nap�t� od "))
rozsah[1,2]<-as.real(readline(" do "))
rozsah[2,1]<-as.real(readline("v_d od "))
rozsah[2,2]<-as.real(readline(" do "))
#rozsah[3,1]<-as.real(readline("v_s od "))
#rozsah[3,2]<-as.real(readline(" do "))
vs1<-as.real(readline("v_s od "))
vs2<-as.real(readline(" do "))
rozsah[3,2]<-kof*rozsah[2,2]/vs1
rozsah[3,1]<-kof*rozsah[2,1]/vs2
#rozsah[3,]<-kof*rozsah[2,]/rozsah[3,]
}
else
{rozsah[1,1]<-min(x1)
rozsah[1,2]<-max(x1)
rozsah[2,1]<-min(x2)
rozsah[2,2]<-max(x2)
vs1<-min(vs)
vs2<-max(vs)
rozsah[3,1]<kof*min(x2)/vs2
rozsah[3,2]<-kof*max(x2)/vs1
}
rozsah[4,1]<-min(Ef)
rozsah[4,2]<-max(Ef)
rozsah[,3]<-(rozsah[,2]-rozsah[,1])/pocet
vs3<-(vs2-vs1)/pocet
rozsah[,4]<-rozsah[,1]+(rozsah[,2]-rozsah[,1])/2
cat("v_t:")
cat("\n")
for (i in 1:n)
{cat(vt[i])
cat("\n")}
cat("E_f:")
cat("\n")
for (i in 1:n)
{cat(Ef[i])
cat("\n")}
pmu<-(max(U)-min(U))/2/sqrt(3)
x1<- (U-min(U))/pmu-sqrt(3)
pmv<-(max(vd)-min(vd))/2/sqrt(3)
x2<- (vd-min(vd))/pmv-sqrt(3)
pmP<-(max(Ps)-min(Ps))/2/sqrt(3)
x3<- (Ps-min(Ps))/pmP-sqrt(3)
pmvs<-(max(vs)-min(vs))/2/sqrt(3)
xv<- (vs-min(vs))/pmvs - sqrt(3)
rozsah2<-matrix(0,3,3)
rozsah2[1,1:2]<-(rozsah[1,1:2]-min(U))/pmu-sqrt(3)
rozsah2[2,1:2]<-(rozsah[2,1:2]-min(vd))/pmv-sqrt(3)
rozsah2[3,1:2]<-(rozsah[3,1:2]-min(Ps))/pmP-sqrt(3)
rozsah2[,3]<-rozsah2[,1]+(rozsah2[,2]-rozsah2[,1])/2
x12<-x1^2
x22<-x2^2
x32<-x3^2
x1x2<-x1*x2
x1x3<-x1*x3
x2x3<-x2*x3
vysl<-summary(lm(Ef ~ x1+ x2+x3+x12+ x22+x32+x1x2+x1x3+x2x3))
print(vysl)
pm<-c("U","v_d","P_s","U^2","v_d^2","P_s^2","v_d*U","U*P_s","v_d*P_s")
cat("E=")
if (vysl$coef[1,4]<0.05) cat(vysl$coef[1,1])
for (i in 1:9) if (vysl$coef[i+1,4]<0.05) cat(ifelse(vysl$coef[i+1,1]>0,"+",""),vysl$coef[i+1,1],pm[i])
cat("\n")
a<--vysl$coef[,1]
#vysl2<-nlminb(c(rozsah[1:3,4]),fun3,lo=c(rozsah[1:3,1]),up=c(rozsah[1:3,2]),a=a)
vysl2<-nlminb(c(rozsah2[1:3,3]),fun3,lo=c(rozsah2[1:3,1]),up=c(rozsah2[1:3,2]),a=a)
opt<-vysl2$par
opt[1]<-(opt[1]+sqrt(3))*pmu+min(U)
opt[2]<-(opt[2]+sqrt(3))*pmv+min(vd)
opt[3]<-(opt[3]+sqrt(3))*pmP+min(Ps)
en<--vysl2$obj
if(nap<0) nap<-opt[1]
nap1<- (nap-min(U))/pmu-sqrt(3)
cat("\n")
cat("Optim�ln� �e�en�:","\n")
#en<--100000
pocet<-pocet+1
data2<-matrix(0,3,pocet)
efe<-matrix(0,pocet,pocet)
for (i in 2:2) data2[i,]<-seq(rozsah[i,1],rozsah[i,2],by=rozsah[i,3])
pmdata<-seq(vs1,vs2,by=vs3)
data2[3,]<-kof*sort(data2[2,],decreasing = TRUE)/pmdata
kde<-expand.grid(nap1, x=(data2[2,]-min(vd))/pmv-sqrt(3), y= (data2[3,]-min(Ps))/pmP-sqrt(3))
#kde<-expand.grid(nap, x=data2[2,], y=data2[3,])
xxx<-as.matrix(cbind(kde,kde[,1]^2,kde[,2]^2,kde[,3]^2,kde[,1]*kde[,2],kde[,1]*kde[,3],kde[,3]*kde[,2]))
efe<-cbind(rep(1,length(xxx[,1])),xxx)%*%vysl$coef[,1]
#en<-max(efe)
#jj<-which.max(efe)
#opt[1]<-xxx[jj,1]
#opt[2]<-xxx[jj,2]
#opt[3]<-xxx[jj,3]
y<-seq(vs1,vs2,by=vs3)
#y<-kof*data2[2,]/data2[3,]
grid<-expand.grid(x=data2[2,], y=y)
grid$z<-efe
cat("E=",en,"\n")
for (i in 1:3) cat(pm[i],"=",opt[i],"\n")
cat("v_s","=",kof*opt[2]/opt[3])
cat("\n")
p1<-contourplot(z~y*x, grid, cuts = vrs, , xlab="vs", ylab="vd", region=T,
main=paste("Efektivita E, U=",round(nap,1)," V",sep=""))
p2<-lpoints(vs,vd)
plot(p1)
#plot(p2)
}
################################
else if(p==2) {
data<-matrix(scan(file), byrow=T, ncol=4)
if(kon<0) kon<-length(data[,1])
data<-data[poc:kon,]
#U<-data[,1]
vd<-data[,1]
vs<-data[,2]
v<-data[,3]
z<-data[,4]
n<-length(vd)
Ps<-kof*vd/vs
vt<-1:n
for (i in 1:n) vt[i]<-uniroot(funHu, low = -1000, up = 1000, tol = 0.01, a=Ps[i], b=z[i])$root
Ef<-z/vt*(v-z)/(vt-z)
rozsah<-matrix(0,4,4)
#x1<-U
x1<-vd
x2<-Ps
odp<-readline("Chce� nastavit rozsahy veli�in (stiskni a v p��pad� ano) ")
if(odp=="a") {
# rozsah[1,1]<-as.real(readline("Nap�t� od "))
# rozsah[1,2]<-as.real(readline(" do "))
rozsah[2,1]<-as.real(readline("v_d od "))
rozsah[2,2]<-as.real(readline(" do "))
vs1<-as.real(readline("v_s od "))
vs2<-as.real(readline(" do "))
rozsah[3,2]<-kof*rozsah[2,2]/vs1
rozsah[3,1]<-kof*rozsah[2,1]/vs2
}
else
{
#rozsah[1,1]<-min(x1)
#rozsah[1,2]<-max(x1)
rozsah[2,1]<-min(x1)
rozsah[2,2]<-max(x1)
rozsah[3,1]<-min(x2)
rozsah[3,2]<-max(x2)
vs1<-min(vs)
vs2<-max(vs)
rozsah[3,1]<kof*min(x2)/vs2
rozsah[3,2]<-kof*max(x2)/vs1
}
rozsah[4,1]<-min(Ef)
rozsah[4,2]<-max(Ef)
rozsah[,3]<-(rozsah[,2]-rozsah[,1])/pocet
vs3<-(vs2-vs1)/pocet
rozsah[,4]<-rozsah[,1]+(rozsah[,2]-rozsah[,1])/2
#print(rozsah)
cat("v_t:")
cat("\n")
for (i in 1:n)
{cat(vt[i])
cat("\n")}
cat("E_f:")
cat("\n")
for (i in 1:n)
{cat(Ef[i])
cat("\n")}
pmv<-(max(vd)-min(vd))/2/sqrt(2)
x1<- (vd-min(vd))/pmv-sqrt(2)
pmP<-(max(Ps)-min(Ps))/2/sqrt(2)
x2<- (Ps-min(Ps))/pmP-sqrt(2)
pmvs<-(max(vs)-min(vs))/2/sqrt(2)
xv<- (vs-min(vs))/pmvs - sqrt(2)
rozsah2<-matrix(0,3,3)
#rozsah2[1,1:2]<-(rozsah[1,1:2]-min(U))/pmu-sqrt(2)
rozsah2[2,1:2]<-(rozsah[2,1:2]-min(vd))/pmv-sqrt(2)
rozsah2[3,1:2]<-(rozsah[3,1:2]-min(Ps))/pmP-sqrt(2)
rozsah2[,3]<-rozsah2[,1]+(rozsah2[,2]-rozsah2[,1])/2
x12<-x1^2
x22<-x2^2
x1x2<-x1*x2
vysl<-summary(lm(Ef ~ x1+ x2+x12+ x22+x1x2))
print(vysl)
pm<-c("v_d","P_s","v_d^2","P_s^2","v_d*P_s")
cat("E=")
if (vysl$coef[1,4]<0.05) cat(vysl$coef[1,1])
for (i in 1:5) if (vysl$coef[i+1,4]<0.05) cat(ifelse(vysl$coef[i+1,1]>0,"+",""),vysl$coef[i+1,1],pm[i])
cat("\n")
a<--vysl$coef[,1]
#vysl2<-nlminb(c(rozsah[2:3,4]),fun2,lo=c(rozsah[2:3,1]),up=c(rozsah[2:3,2]),a=a)
vysl2<-nlminb(c(rozsah2[2:3,3]),fun2,lo=c(rozsah2[2:3,1]),up=c(rozsah2[2:3,2]),a=a)
opt<-vysl2$par
#opt[1]<-(opt[1]+sqrt(2))*pmu+min(U)
opt[1]<-(opt[1]+sqrt(2))*pmv+min(vd)
opt[2]<-(opt[2]+sqrt(2))*pmP+min(Ps)
en<--vysl2$obj
#if(nap<0) nap<-opt[1]
cat("\n")
cat("Optim�ln� �e�en�:","\n")
#en<--100000
pocet<-pocet+1
data2<-matrix(0,3,pocet)
efe<-matrix(0,pocet,pocet)
for (i in 2:2) data2[i,]<-seq(rozsah[i,1],rozsah[i,2],by=rozsah[i,3])
pmdata<-seq(vs1,vs2,by=vs3)
data2[3,]<-kof*sort(data2[2,],decreasing = TRUE)/pmdata
#for (i in 2:3) data2[i,]<-seq(rozsah[i,1],rozsah[i,2],by=rozsah[i,3])
#kde<-expand.grid(x=data2[2,], y=data2[3,])
kde<-expand.grid(x=(data2[2,]-min(vd))/pmv-sqrt(2), y= (data2[3,]-min(Ps))/pmP-sqrt(2))
xxx<-as.matrix(cbind(kde,kde[,1]^2,kde[,2]^2,kde[,1]*kde[,2]))
efe<-cbind(rep(1,length(xxx[,1])),xxx)%*%vysl$coef[,1]
#en<-max(efe)
#jj<-which.max(efe)
#opt[1]<-xxx[jj,1]
#opt[2]<-xxx[jj,2]
#opt[3]<-xxx[jj,3]
y<-seq(vs1,vs2,by=vs3)
#y<-kof*data2[2,]/data2[3,]
grid<-expand.grid(x=data2[2,], y=y)
grid$z<-efe
cat("E=",en,"\n")
for (i in 1:2) cat(pm[i],"=",opt[i],"\n")
cat("v_s","=",kof*opt[1]/opt[2])
cat("\n")
p1<-contourplot(z~y*x, grid, cuts = vrs, , xlab="vs", ylab="vd", region=T, main=paste("Efektivita E ",sep=""))
#p2<-lpoints(vs,vd)
plot(p1)
#plot(p2)
}
else if (p==4) {
data<-matrix(scan(file), byrow=T, ncol=6)
if(kon<0) kon<-length(data[,1])
data<-data[poc:kon,]
U<-data[,1]
vd<-data[,2]
vs<-data[,3]
v<-data[,4]
z<-data[,5]
ctv<-data[,6]
n<-length(vd)
Ps<-kof*vd/vs
vt<-1:n
for (i in 1:n) vt[i]<-uniroot(funHu, low = -1000, up = 1000, tol = 0.01, a=Ps[i], b=z[i])$root
Ef<-z/vt*(v-z)/(vt-z)
rozsah<-matrix(0,5,4)
x1<-U
x2<-vd
x3<-Ps
x4<-ctv
odp<-readline("Chce� nastavit rozsahy veli�in (stiskni a v p��pad� ano) ")
if(odp=="a") {
rozsah[1,1]<-as.real(readline("Nap�t� od "))
rozsah[1,2]<-as.real(readline(" do "))
rozsah[2,1]<-as.real(readline("v_d od "))
rozsah[2,2]<-as.real(readline(" do "))
rozsah[3,1]<-as.real(readline("v_s od "))
rozsah[3,2]<-as.real(readline(" do "))
rozsah[3,]<-kof*rozsah[2,]/rozsah[3,]
}
else
{rozsah[1,1]<-min(x1)
rozsah[1,2]<-max(x1)
rozsah[2,1]<-min(x2)
rozsah[2,2]<-max(x2)
rozsah[3,1]<-min(x3)
rozsah[3,2]<-max(x3)
}
rozsah[4,1]<-min(x4)
rozsah[4,2]<-max(x4)
rozsah[5,1]<-min(Ef)
rozsah[5,2]<-max(Ef)
rozsah[,3]<-(rozsah[,2]-rozsah[,1])/pocet
rozsah[,4]<-rozsah[,1]+(rozsah[,2]-rozsah[,1])/2
cat("v_t:")
print(vt)
x12<-x1^2
x22<-x2^2
x32<-x3^2
x42<-x4^2
x1x2<-x1*x2
x1x3<-x1*x3
x1x4<-x1*x4
x2x3<-x2*x3
x2x4<-x2*x4
x3x4<-x3*x4
vysl<-summary(lm(Ef ~ x1+ x2+x3+x4+x12+ x22+x32+x42+x1x2+x1x3+x1x4+x2x3+x2x4+x3x4))
print(vysl)
pm<-c("U","v_d","P_s","par4","U^2","v_d^2","P_s^2","par4^2","v_d*U","U*P_s","U*par4", "v_d*P_s","v_d*par4","P_s*par4")
cat("E=")
if (vysl$coef[1,4]<0.05) cat(vysl$coef[1,1])
for (i in 1:14) if (vysl$coef[i+1,4]<0.05) cat(ifelse(vysl$coef[i+1,1]>0,"+",""),vysl$coef[i+1,1],pm[i])
cat("\n")
a<--vysl$coef[,1]
vysl2<-nlminb(c(rozsah[1:3,4]),fun4,lo=c(rozsah[1:3,1]),up=c(rozsah[1:3,2]),a=a)
opt<-vysl2$par
en<--vysl2$obj
if(nap<0) nap<-opt[1]
cat("\n")
cat("Optim�ln� �e�en�:","\n")
#en<--100000
pocet<-pocet+1
data2<-matrix(0,4,pocet)
efe<-matrix(0,pocet,pocet)
for (i in 2:4) data2[i,]<-seq(rozsah[i,1],rozsah[i,2],by=rozsah[i,3])
kde<-expand.grid(nap, x=data2[2,], y=data2[3,], z=data2[4,])
xxx<-as.matrix(cbind(kde,kde[,1]^2,kde[,2]^2,kde[,3]^2,kde[,4]^2,kde[,1]*kde[,2],kde[,1]*kde[,3],kde[,1]*kde[,4],
kde[,3]*kde[,2],kde[,2]*kde[,4],kde[,4]*kde[,3]))
efe<-cbind(rep(1,length(xxx[,1])),xxx)%*%vysl$coef[,1]
#en<-max(efe)
#jj<-which.max(efe)
#opt[1]<-xxx[jj,1]
#opt[2]<-xxx[jj,2]
#opt[3]<-xxx[jj,3]
y<-kof*data2[2,]/data2[3,]
grid<-expand.grid(x=data2[2,], y=y)
grid$z<-efe
cat("E=",en,"\n")
for (i in 1:4) cat(pm[i],"=",opt[i],"\n")
cat("v_s","=",kof*opt[2]/opt[3])
cat("\n")
p1<- contourplot(z~y*x, grid, cuts = 10, , xlab="vs", ylab="vd", region=T,
main=paste("Efektivita E, U=",round(nap,1)," V",sep=""))
p2<-lpoints(vs,vd)
plot(p1)
#plot(p2)
}
else cat("�patn� zad�n�")
}
analyza2<-function(file="c:\\Opt2.txt",nap=-1,poc=1,kon=-1,pocet=100,kof=1.04)
{
library(grDevices)
library(lattice)
options(warn=-5)
p<-as.integer(readline("zadej po�et parametr� "))
############
if(p==3) {
data<-matrix(scan(file), byrow=T, ncol=5)
if(kon<0) kon<-length(data[,1])
data<-data[poc:kon,]
U<-data[,1]
vd<-data[,2]
vs<-data[,3]
v<-data[,4]
z<-data[,5]
n<-length(vd)
Ps<-kof*vd/vs
vt<-1:n
for (i in 1:n) vt[i]<-uniroot(funHu, low = -1000, up = 1000, tol = 0.01, a=Ps[i], b=z[i])$root
Ef<-z/vt*(v-z)/(vt-z)
rozsah<-matrix(0,4,4)
x1<-U
x2<-vd
x3<-Ps
odp<-readline("Chce� nastavit rozsahy veli�in (stiskni a v p��pad� ano) ")
if(odp=="a") {
rozsah[1,1]<-as.real(readline("Nap�t� od "))
rozsah[1,2]<-as.real(readline(" do "))
rozsah[2,1]<-as.real(readline("v_d od "))
rozsah[2,2]<-as.real(readline(" do "))
#rozsah[3,1]<-as.real(readline("v_s od "))
#rozsah[3,2]<-as.real(readline(" do "))
vs1<-as.real(readline("v_s od "))
vs2<-as.real(readline(" do "))
rozsah[3,2]<-kof*rozsah[2,2]/vs1
rozsah[3,1]<-kof*rozsah[2,1]/vs2
#rozsah[3,]<-kof*rozsah[2,]/rozsah[3,]
}
else
{rozsah[1,1]<-min(x1)
rozsah[1,2]<-max(x1)
rozsah[2,1]<-min(x2)
rozsah[2,2]<-max(x2)
vs1<-min(vs)
vs2<-max(vs)
rozsah[3,1]<kof*min(x2)/vs2
rozsah[3,2]<-kof*max(x2)/vs1
}
rozsah[4,1]<-min(Ef)
rozsah[4,2]<-max(Ef)
rozsah[,3]<-(rozsah[,2]-rozsah[,1])/pocet
vs3<-(vs2-vs1)/pocet
rozsah[,4]<-rozsah[,1]+(rozsah[,2]-rozsah[,1])/2
cat("v_t:")
cat("\n")
for (i in 1:n)
{cat(vt[i])
cat("\n")}
cat("E_f:")
cat("\n")
for (i in 1:n)
{cat(Ef[i])
cat("\n")}
pmu<-(max(U)-min(U))/2/sqrt(3)
x1<- (U-min(U))/pmu-sqrt(3)
pmv<-(max(vd)-min(vd))/2/sqrt(3)
x2<- (vd-min(vd))/pmv-sqrt(3)
pmP<-(max(Ps)-min(Ps))/2/sqrt(3)
x3<- (Ps-min(Ps))/pmP-sqrt(3)
pmvs<-(max(vs)-min(vs))/2/sqrt(3)
xv<- (vs-min(vs))/pmvs - sqrt(3)
rozsah2<-matrix(0,3,3)
rozsah2[1,1:2]<-(rozsah[1,1:2]-min(U))/pmu-sqrt(3)
rozsah2[2,1:2]<-(rozsah[2,1:2]-min(vd))/pmv-sqrt(3)
rozsah2[3,1:2]<-(rozsah[3,1:2]-min(Ps))/pmP-sqrt(3)
rozsah2[,3]<-rozsah2[,1]+(rozsah2[,2]-rozsah2[,1])/2
x12<-x1^2
x22<-x2^2
x32<-x3^2
x1x2<-x1*x2
x1x3<-x1*x3
x2x3<-x2*x3
vysl<-summary(lm(Ef ~ x1+ x2+x3+x12+ x22+x32+x1x2+x1x3+x2x3))
print(vysl)
pm<-c("U","v_d","P_s","U^2","v_d^2","P_s^2","v_d*U","U*P_s","v_d*P_s")
cat("E=")
if (vysl$coef[1,4]<0.05) cat(vysl$coef[1,1])
for (i in 1:9) if (vysl$coef[i+1,4]<0.05) cat(ifelse(vysl$coef[i+1,1]>0,"+",""),vysl$coef[i+1,1],pm[i])
cat("\n")
a<--vysl$coef[,1]
#vysl2<-nlminb(c(rozsah[1:3,4]),fun3,lo=c(rozsah[1:3,1]),up=c(rozsah[1:3,2]),a=a)
vysl2<-nlminb(c(rozsah2[1:3,3]),fun3,lo=c(rozsah2[1:3,1]),up=c(rozsah2[1:3,2]),a=a)
opt<-vysl2$par
opt[1]<-(opt[1]+sqrt(3))*pmu+min(U)
opt[2]<-(opt[2]+sqrt(3))*pmv+min(vd)
opt[3]<-(opt[3]+sqrt(3))*pmP+min(Ps)
en<--vysl2$obj
if(nap<0) nap<-opt[1]
nap1<- (nap-min(U))/pmu-sqrt(3)
cat("\n")
cat("Optim�ln� �e�en�:","\n")
#en<--100000
pocet<-pocet+1
data2<-matrix(0,3,pocet)
efe<-matrix(0,pocet,pocet)
for (i in 2:2) data2[i,]<-seq(rozsah[i,1],rozsah[i,2],by=rozsah[i,3])
pmdata<-seq(vs1,vs2,by=vs3)
data2[3,]<-kof*sort(data2[2,],decreasing = TRUE)/pmdata
kde<-expand.grid(nap1, x=(data2[2,]-min(vd))/pmv-sqrt(3), y= (data2[3,]-min(Ps))/pmP-sqrt(3))
#kde<-expand.grid(nap, x=data2[2,], y=data2[3,])
xxx<-as.matrix(cbind(kde,kde[,1]^2,kde[,2]^2,kde[,3]^2,kde[,1]*kde[,2],kde[,1]*kde[,3],kde[,3]*kde[,2]))
efe<-cbind(rep(1,length(xxx[,1])),xxx)%*%vysl$coef[,1]
#en<-max(efe)
#jj<-which.max(efe)
#opt[1]<-xxx[jj,1]
#opt[2]<-xxx[jj,2]
#opt[3]<-xxx[jj,3]
y<-seq(vs1,vs2,by=vs3)
#y<-kof*data2[2,]/data2[3,]
grid<-expand.grid(x=data2[2,], y=y)
grid$z<-efe
cat("E=",en,"\n")
for (i in 1:3) cat(pm[i],"=",opt[i],"\n")
cat("v_s","=",kof*opt[2]/opt[3])
cat("\n")
wireframe(z~y*x, grid, xlab="vs", ylab="vd", zlab="E",
main=paste("Efektivita E, U=",nap," V",sep=""), drape = T)
}
################################
else if(p==2) {
data<-matrix(scan(file), byrow=T, ncol=4)
if(kon<0) kon<-length(data[,1])
data<-data[poc:kon,]
#U<-data[,1]
vd<-data[,1]
vs<-data[,2]
v<-data[,3]
z<-data[,4]
n<-length(vd)
Ps<-kof*vd/vs
vt<-1:n
for (i in 1:n) vt[i]<-uniroot(funHu, low = -1000, up = 1000, tol = 0.01, a=Ps[i], b=z[i])$root
Ef<-z/vt*(v-z)/(vt-z)
rozsah<-matrix(0,4,4)
#x1<-U
x1<-vd
x2<-Ps
odp<-readline("Chce� nastavit rozsahy veli�in (stiskni a v p��pad� ano) ")
if(odp=="a") {
# rozsah[1,1]<-as.real(readline("Nap�t� od "))
# rozsah[1,2]<-as.real(readline(" do "))
rozsah[2,1]<-as.real(readline("v_d od "))
rozsah[2,2]<-as.real(readline(" do "))
vs1<-as.real(readline("v_s od "))
vs2<-as.real(readline(" do "))
rozsah[3,2]<-kof*rozsah[2,2]/vs1
rozsah[3,1]<-kof*rozsah[2,1]/vs2
}
else
{
#rozsah[1,1]<-min(x1)
#rozsah[1,2]<-max(x1)
rozsah[2,1]<-min(x1)
rozsah[2,2]<-max(x1)
rozsah[3,1]<-min(x2)
rozsah[3,2]<-max(x2)
vs1<-min(vs)
vs2<-max(vs)
rozsah[3,1]<kof*min(x2)/vs2
rozsah[3,2]<-kof*max(x2)/vs1
}
rozsah[4,1]<-min(Ef)
rozsah[4,2]<-max(Ef)
rozsah[,3]<-(rozsah[,2]-rozsah[,1])/pocet
vs3<-(vs2-vs1)/pocet
rozsah[,4]<-rozsah[,1]+(rozsah[,2]-rozsah[,1])/2
#print(rozsah)
cat("v_t:")
cat("\n")
for (i in 1:n)
{cat(vt[i])
cat("\n")}
cat("E_f:")
cat("\n")
for (i in 1:n)
{cat(Ef[i])
cat("\n")}
pmv<-(max(vd)-min(vd))/2/sqrt(2)
x1<- (vd-min(vd))/pmv-sqrt(2)
pmP<-(max(Ps)-min(Ps))/2/sqrt(2)
x2<- (Ps-min(Ps))/pmP-sqrt(2)
pmvs<-(max(vs)-min(vs))/2/sqrt(2)
xv<- (vs-min(vs))/pmvs - sqrt(2)
rozsah2<-matrix(0,3,3)
#rozsah2[1,1:2]<-(rozsah[1,1:2]-min(U))/pmu-sqrt(2)
rozsah2[2,1:2]<-(rozsah[2,1:2]-min(vd))/pmv-sqrt(2)
rozsah2[3,1:2]<-(rozsah[3,1:2]-min(Ps))/pmP-sqrt(2)
rozsah2[,3]<-rozsah2[,1]+(rozsah2[,2]-rozsah2[,1])/2
x12<-x1^2
x22<-x2^2
x1x2<-x1*x2
vysl<-summary(lm(Ef ~ x1+ x2+x12+ x22+x1x2))
print(vysl)
pm<-c("v_d","P_s","v_d^2","P_s^2","v_d*P_s")
cat("E=")
if (vysl$coef[1,4]<0.05) cat(vysl$coef[1,1])
for (i in 1:5) if (vysl$coef[i+1,4]<0.05) cat(ifelse(vysl$coef[i+1,1]>0,"+",""),vysl$coef[i+1,1],pm[i])
cat("\n")
a<--vysl$coef[,1]
#vysl2<-nlminb(c(rozsah[2:3,4]),fun2,lo=c(rozsah[2:3,1]),up=c(rozsah[2:3,2]),a=a)
vysl2<-nlminb(c(rozsah2[2:3,3]),fun2,lo=c(rozsah2[2:3,1]),up=c(rozsah2[2:3,2]),a=a)
opt<-vysl2$par
#opt[1]<-(opt[1]+sqrt(2))*pmu+min(U)
opt[1]<-(opt[1]+sqrt(2))*pmv+min(vd)
opt[2]<-(opt[2]+sqrt(2))*pmP+min(Ps)
en<--vysl2$obj
#if(nap<0) nap<-opt[1]
cat("\n")
cat("Optim�ln� �e�en�:","\n")
#en<--100000
pocet<-pocet+1
data2<-matrix(0,3,pocet)
efe<-matrix(0,pocet,pocet)
for (i in 2:2) data2[i,]<-seq(rozsah[i,1],rozsah[i,2],by=rozsah[i,3])
pmdata<-seq(vs1,vs2,by=vs3)
data2[3,]<-kof*sort(data2[2,],decreasing = TRUE)/pmdata
#for (i in 2:3) data2[i,]<-seq(rozsah[i,1],rozsah[i,2],by=rozsah[i,3])
#kde<-expand.grid(x=data2[2,], y=data2[3,])
kde<-expand.grid(x=(data2[2,]-min(vd))/pmv-sqrt(2), y= (data2[3,]-min(Ps))/pmP-sqrt(2))
xxx<-as.matrix(cbind(kde,kde[,1]^2,kde[,2]^2,kde[,1]*kde[,2]))
efe<-cbind(rep(1,length(xxx[,1])),xxx)%*%vysl$coef[,1]
#en<-max(efe)
#jj<-which.max(efe)
#opt[1]<-xxx[jj,1]
#opt[2]<-xxx[jj,2]
#opt[3]<-xxx[jj,3]
y<-seq(vs1,vs2,by=vs3)
#y<-kof*data2[2,]/data2[3,]
grid<-expand.grid(x=data2[2,], y=y)
grid$z<-efe
cat("E=",en,"\n")
for (i in 1:2) cat(pm[i],"=",opt[i],"\n")
cat("v_s","=",kof*opt[1]/opt[2])
cat("\n")
wireframe(z~y*x, grid, xlab="vs", ylab="vd", zlab="E",
main=paste("Efektivita E",sep=""), drape = T)
}
else if (p==4) {
data<-matrix(scan(file), byrow=T, ncol=6)
if(kon<0) kon<-length(data[,1])
data<-data[poc:kon,]
U<-data[,1]
vd<-data[,2]
vs<-data[,3]
v<-data[,4]
z<-data[,5]
ctv<-data[,6]
n<-length(vd)
Ps<-kof*vd/vs
vt<-1:n
for (i in 1:n) vt[i]<-uniroot(funHu, low = -1000, up = 1000, tol = 0.01, a=Ps[i], b=z[i])$root
Ef<-z/vt*(v-z)/(vt-z)
rozsah<-matrix(0,5,4)
x1<-U
x2<-vd
x3<-Ps
x4<-ctv
odp<-readline("Chce� nastavit rozsahy veli�in (stiskni a v p��pad� ano) ")
if(odp=="a") {
rozsah[1,1]<-as.real(readline("Nap�t� od "))
rozsah[1,2]<-as.real(readline(" do "))
rozsah[2,1]<-as.real(readline("v_d od "))
rozsah[2,2]<-as.real(readline(" do "))
rozsah[3,1]<-as.real(readline("v_s od "))
rozsah[3,2]<-as.real(readline(" do "))
rozsah[3,]<-kof*rozsah[2,]/rozsah[3,]
}
else
{rozsah[1,1]<-min(x1)
rozsah[1,2]<-max(x1)
rozsah[2,1]<-min(x2)
rozsah[2,2]<-max(x2)
rozsah[3,1]<-min(x3)
rozsah[3,2]<-max(x3)
}
rozsah[4,1]<-min(x4)
rozsah[4,2]<-max(x4)
rozsah[5,1]<-min(Ef)
rozsah[5,2]<-max(Ef)
rozsah[,3]<-(rozsah[,2]-rozsah[,1])/pocet
rozsah[,4]<-rozsah[,1]+(rozsah[,2]-rozsah[,1])/2
cat("v_t:")
print(vt)
x12<-x1^2
x22<-x2^2
x32<-x3^2
x42<-x4^2
x1x2<-x1*x2
x1x3<-x1*x3
x1x4<-x1*x4
x2x3<-x2*x3
x2x4<-x2*x4
x3x4<-x3*x4
vysl<-summary(lm(Ef ~ x1+ x2+x3+x4+x12+ x22+x32+x42+x1x2+x1x3+x1x4+x2x3+x2x4+x3x4))
print(vysl)
pm<-c("U","v_d","P_s","par4","U^2","v_d^2","P_s^2","par4^2","v_d*U","U*P_s","U*par4", "v_d*P_s","v_d*par4","P_s*par4")
cat("E=")
if (vysl$coef[1,4]<0.05) cat(vysl$coef[1,1])
for (i in 1:14) if (vysl$coef[i+1,4]<0.05) cat(ifelse(vysl$coef[i+1,1]>0,"+",""),vysl$coef[i+1,1],pm[i])
cat("\n")
a<--vysl$coef[,1]
vysl2<-nlminb(c(rozsah[1:3,4]),fun4,lo=c(rozsah[1:3,1]),up=c(rozsah[1:3,2]),a=a)
opt<-vysl2$par
en<--vysl2$obj
if(nap<0) nap<-opt[1]
cat("\n")
cat("Optim�ln� �e�en�:","\n")
#en<--100000
pocet<-pocet+1
data2<-matrix(0,4,pocet)
efe<-matrix(0,pocet,pocet)
for (i in 2:4) data2[i,]<-seq(rozsah[i,1],rozsah[i,2],by=rozsah[i,3])
kde<-expand.grid(nap, x=data2[2,], y=data2[3,], z=data2[4,])
xxx<-as.matrix(cbind(kde,kde[,1]^2,kde[,2]^2,kde[,3]^2,kde[,4]^2,kde[,1]*kde[,2],kde[,1]*kde[,3],kde[,1]*kde[,4],
kde[,3]*kde[,2],kde[,2]*kde[,4],kde[,4]*kde[,3]))
efe<-cbind(rep(1,length(xxx[,1])),xxx)%*%vysl$coef[,1]
#en<-max(efe)
#jj<-which.max(efe)
#opt[1]<-xxx[jj,1]
#opt[2]<-xxx[jj,2]
#opt[3]<-xxx[jj,3]
y<-kof*data2[2,]/data2[3,]
grid<-expand.grid(x=data2[2,], y=y)
grid$z<-efe
cat("E=",en,"\n")
for (i in 1:4) cat(pm[i],"=",opt[i],"\n")
cat("v_s","=",kof*opt[2]/opt[3])
cat("\n")
wireframe(z~y*x, grid, xlab="vs", ylab="vd", zlab="E",
main=paste("Efektivita E, U=",nap," V",sep=""), drape = T)
}
else cat("�patn� zad�n�")
}
analyza3<-function(file="c:\\Opt2.txt",poc=1,kon=-1,kof=1.04)
{
library(grDevices)
library(lattice)
options(warn=-5)
p<-as.integer(readline("zadej po�et parametr� "))
if(p==3) {
data<-matrix(scan(file), byrow=T, ncol=5)
if(kon<0) kon<-length(data[,1])
data<-data[poc:kon,]
vd<-data[,2]
vs<-data[,3]
z<-data[,5]
n<-length(vd)
Ps<-kof*vd/vs}
else if(p==2) {
data<-matrix(scan(file), byrow=T, ncol=4)
if(kon<0) kon<-length(data[,1])
data<-data[poc:kon,]
vd<-data[,1]
vs<-data[,2]
z<-data[,4]
n<-length(vd)
Ps<-kof*vd/vs
}
else if (p==4) {
data<-matrix(scan(file), byrow=T, ncol=6)
if(kon<0) kon<-length(data[,1])
data<-data[poc:kon,]
vd<-data[,2]
vs<-data[,3]
z<-data[,5]
n<-length(vd)
Ps<-kof*vd/vs
}
else cat("�patn� zad�n�")
if (p==2 | p==3 | p==4){
odp<-readline("Chce� nastavit rozsahy veli�in (stiskni a v p��pad� ano) ")
if(odp=="a") {
zd<-as.real(readline("Z�var od "))
zh<-as.real(readline(" do "))
Pd<-as.real(readline("Plocha od "))
Ph<-as.real(readline(" do "))
}
else
{zd<-min(z)-0.1
zh<-max(z)+0.1
Pd<-min(round(Ps,1))-0.2
Ph<-max(round(Ps,1))+0.2
}
plot(Ps~z,pch=4,xlab="z�var",ylab="Plocha",axes=FALSE,xlim=c(zd,zh),ylim=c(Pd,Ph))
for (i in 1:n) text(z[i]+0.03,Ps[i]-0.03,i)
axis(1, seq(zd,zh,by=0.1))
axis(2, seq(trunc(Pd),ceiling(Ph),by=0.5),las=1)
box()
mtext("efektivn� nosn� velikost vt",side=3,col="blue",line=0.5)
mtext("efektivita z�varu Ez",side=4,col="green",line=0.5)
grid(lwd = 2)
zz<-seq(zd,zh,by=0.01)
for (i in seq(4.0,14.0,by=0.1)){
pm<-i*(i-zz)^2/sqrt(i^2-zz^2)
lines(pm~zz,col="blue")
}
for (i in seq(4.6,14.0,by=0.2)) {pzz<-uniroot(funHu2, low = i-6, up = i-2, tol = 0.01, a=Ph, b=i)$root
text(pzz,Ph,i,col="blue")}
for (i in seq(0.3,0.8,by=0.01)){
vtt<-zz/i
pm2<-vtt*(vtt-zz)^2/sqrt(vtt^2-zz^2)
lines(pm2~zz,col="green")
}
for (i in seq(0.3,0.8,by=0.03)){
pzz<-uniroot(funHu3, low = 0.5, up = 14.25, tol = 0.01, a=Pd, b=i)$root
text(pzz,Pd,i,col="green")
}
}
}
uroven<-function(dh, hh)
{
jedn<-(hh-dh)/2/sqrt(3)
pm<-rep(0,5)
pm[1]<-dh
pm[5]<-hh
pm[3]<-(dh+hh)/2
pm[2]<-pm[3]-jedn
pm[4]<-pm[3]+jedn
pm
}
funHu<- function (x,a,b ) a-x*(x-b)^2/sqrt(x^2-b^2)
funHu2<- function (x,a,b ) a-b*(b-x)^2/sqrt(b^2-x^2)
funHu3<- function (x,a,b ) a-x/b*(x/b-x)^2/sqrt((x/b)^2-x^2)
fun3<-function(x,a) {
x1<-x[1]
x2<-x[2]
x3<-x[3]
a[1]+a[2]*x1+ a[3]*x2+a[4]*x3+a[5]*x1^2+ a[6]*x2^2+a[7]*x3^2+a[8]*x1*x2+a[9]*x1*x3+a[10]*x2*x3
}
fun4<-function(x,a) {
x1<-x[1]
x2<-x[2]
x3<-x[3]
x4<-x[4]
a[1]+a[2]*x1+ a[3]*x2+a[4]*x3+a[5]*x4+a[6]*x1^2+ a[7]*x2^2+a[8]*x3^2+a[9]*x4^2+a[10]*x1*x2+a[11]*x1*x3+
a[12]*x1*x4+a[13]*x2*x3+a[14]*x2*x4+a[15]*x3*x4
}
fun2<-function(x,a) {
x1<-x[1]
x2<-x[2]
a[1]+a[2]*x1+ a[3]*x2+a[4]*x1^2+ a[5]*x2^2+a[6]*x1*x2
}
#zadej k, implicitn� je 1.04 #zadej U, vd,vs, v, z analyza<-function(file="c:\\Opt2.txt",nap=-1,vrs=15,poc=1,kon=-1,pocet=100,kof=1.04) { library(grDevices) library(lattice) options(warn=-5) p<-as.integer(readline("zadej po�et parametr� ")) ############ if(p==3) { data<-matrix(scan(file), byrow=T, ncol=5) if(kon<0) kon<-length(data[,1]) data<-data[poc:kon,] U<-data[,1] vd<-data[,2] vs<-data[,3] v<-data[,4] z<-data[,5] n<-length(vd) Ps<-kof*vd/vs vt<-1:n for (i in 1:n) vt[i]<-uniroot(funHu, low = -1000, up = 1000, tol = 0.01, a=Ps[i], b=z[i])$root Ef<-z/vt*(v-z)/(vt-z) rozsah<-matrix(0,4,4) x1<-U x2<-vd x3<-Ps odp<-readline("Chce� nastavit rozsahy veli�in (stiskni a v p��pad� ano) ") if(odp=="a") { rozsah[1,1]<-as.real(readline("Nap�t� od ")) rozsah[1,2]<-as.real(readline(" do ")) rozsah[2,1]<-as.real(readline("v_d od ")) rozsah[2,2]<-as.real(readline(" do ")) #rozsah[3,1]<-as.real(readline("v_s od ")) #rozsah[3,2]<-as.real(readline(" do ")) vs1<-as.real(readline("v_s od ")) vs2<-as.real(readline(" do ")) rozsah[3,2]<-kof*rozsah[2,2]/vs1 rozsah[3,1]<-kof*rozsah[2,1]/vs2 #rozsah[3,]<-kof*rozsah[2,]/rozsah[3,] } else {rozsah[1,1]<-min(x1) rozsah[1,2]<-max(x1) rozsah[2,1]<-min(x2) rozsah[2,2]<-max(x2) vs1<-min(vs) vs2<-max(vs) rozsah[3,1]<kof*min(x2)/vs2 rozsah[3,2]<-kof*max(x2)/vs1 } rozsah[4,1]<-min(Ef) rozsah[4,2]<-max(Ef) rozsah[,3]<-(rozsah[,2]-rozsah[,1])/pocet vs3<-(vs2-vs1)/pocet rozsah[,4]<-rozsah[,1]+(rozsah[,2]-rozsah[,1])/2 cat("v_t:") cat("\n") for (i in 1:n) {cat(vt[i]) cat("\n")} cat("E_f:") cat("\n") for (i in 1:n) {cat(Ef[i]) cat("\n")} pmu<-(max(U)-min(U))/2/sqrt(3) x1<- (U-min(U))/pmu-sqrt(3) pmv<-(max(vd)-min(vd))/2/sqrt(3) x2<- (vd-min(vd))/pmv-sqrt(3) pmP<-(max(Ps)-min(Ps))/2/sqrt(3) x3<- (Ps-min(Ps))/pmP-sqrt(3) pmvs<-(max(vs)-min(vs))/2/sqrt(3) xv<- (vs-min(vs))/pmvs - sqrt(3) rozsah2<-matrix(0,3,3) rozsah2[1,1:2]<-(rozsah[1,1:2]-min(U))/pmu-sqrt(3) rozsah2[2,1:2]<-(rozsah[2,1:2]-min(vd))/pmv-sqrt(3) rozsah2[3,1:2]<-(rozsah[3,1:2]-min(Ps))/pmP-sqrt(3) rozsah2[,3]<-rozsah2[,1]+(rozsah2[,2]-rozsah2[,1])/2 x12<-x1^2 x22<-x2^2 x32<-x3^2 x1x2<-x1*x2 x1x3<-x1*x3 x2x3<-x2*x3 vysl<-summary(lm(Ef ~ x1+ x2+x3+x12+ x22+x32+x1x2+x1x3+x2x3)) print(vysl) pm<-c("U","v_d","P_s","U^2","v_d^2","P_s^2","v_d*U","U*P_s","v_d*P_s") cat("E=") if (vysl$coef[1,4]<0.05) cat(vysl$coef[1,1]) for (i in 1:9) if (vysl$coef[i+1,4]<0.05) cat(ifelse(vysl$coef[i+1,1]>0,"+",""),vysl$coef[i+1,1],pm[i]) cat("\n") a<--vysl$coef[,1] #vysl2<-nlminb(c(rozsah[1:3,4]),fun3,lo=c(rozsah[1:3,1]),up=c(rozsah[1:3,2]),a=a) vysl2<-nlminb(c(rozsah2[1:3,3]),fun3,lo=c(rozsah2[1:3,1]),up=c(rozsah2[1:3,2]),a=a) opt<-vysl2$par opt[1]<-(opt[1]+sqrt(3))*pmu+min(U) opt[2]<-(opt[2]+sqrt(3))*pmv+min(vd) opt[3]<-(opt[3]+sqrt(3))*pmP+min(Ps) en<--vysl2$obj if(nap<0) nap<-opt[1] nap1<- (nap-min(U))/pmu-sqrt(3) cat("\n") cat("Optim�ln� �e�en�:","\n") #en<--100000 pocet<-pocet+1 data2<-matrix(0,3,pocet) efe<-matrix(0,pocet,pocet) for (i in 2:2) data2[i,]<-seq(rozsah[i,1],rozsah[i,2],by=rozsah[i,3]) pmdata<-seq(vs1,vs2,by=vs3) data2[3,]<-kof*sort(data2[2,],decreasing = TRUE)/pmdata kde<-expand.grid(nap1, x=(data2[2,]-min(vd))/pmv-sqrt(3), y= (data2[3,]-min(Ps))/pmP-sqrt(3)) #kde<-expand.grid(nap, x=data2[2,], y=data2[3,]) xxx<-as.matrix(cbind(kde,kde[,1]^2,kde[,2]^2,kde[,3]^2,kde[,1]*kde[,2],kde[,1]*kde[,3],kde[,3]*kde[,2])) efe<-cbind(rep(1,length(xxx[,1])),xxx)%*%vysl$coef[,1] #en<-max(efe) #jj<-which.max(efe) #opt[1]<-xxx[jj,1] #opt[2]<-xxx[jj,2] #opt[3]<-xxx[jj,3] y<-seq(vs1,vs2,by=vs3) #y<-kof*data2[2,]/data2[3,] grid<-expand.grid(x=data2[2,], y=y) grid$z<-efe cat("E=",en,"\n") for (i in 1:3) cat(pm[i],"=",opt[i],"\n") cat("v_s","=",kof*opt[2]/opt[3]) cat("\n") p1<-contourplot(z~y*x, grid, cuts = vrs, , xlab="vs", ylab="vd", region=T, main=paste("Efektivita E, U=",round(nap,1)," V",sep="")) p2<-lpoints(vs,vd) plot(p1) #plot(p2) } ################################ else if(p==2) { data<-matrix(scan(file), byrow=T, ncol=4) if(kon<0) kon<-length(data[,1]) data<-data[poc:kon,] #U<-data[,1] vd<-data[,1] vs<-data[,2] v<-data[,3] z<-data[,4] n<-length(vd) Ps<-kof*vd/vs vt<-1:n for (i in 1:n) vt[i]<-uniroot(funHu, low = -1000, up = 1000, tol = 0.01, a=Ps[i], b=z[i])$root Ef<-z/vt*(v-z)/(vt-z) rozsah<-matrix(0,4,4) #x1<-U x1<-vd x2<-Ps odp<-readline("Chce� nastavit rozsahy veli�in (stiskni a v p��pad� ano) ") if(odp=="a") { # rozsah[1,1]<-as.real(readline("Nap�t� od ")) # rozsah[1,2]<-as.real(readline(" do ")) rozsah[2,1]<-as.real(readline("v_d od ")) rozsah[2,2]<-as.real(readline(" do ")) vs1<-as.real(readline("v_s od ")) vs2<-as.real(readline(" do ")) rozsah[3,2]<-kof*rozsah[2,2]/vs1 rozsah[3,1]<-kof*rozsah[2,1]/vs2 } else { #rozsah[1,1]<-min(x1) #rozsah[1,2]<-max(x1) rozsah[2,1]<-min(x1) rozsah[2,2]<-max(x1) rozsah[3,1]<-min(x2) rozsah[3,2]<-max(x2) vs1<-min(vs) vs2<-max(vs) rozsah[3,1]<kof*min(x2)/vs2 rozsah[3,2]<-kof*max(x2)/vs1 } rozsah[4,1]<-min(Ef) rozsah[4,2]<-max(Ef) rozsah[,3]<-(rozsah[,2]-rozsah[,1])/pocet vs3<-(vs2-vs1)/pocet rozsah[,4]<-rozsah[,1]+(rozsah[,2]-rozsah[,1])/2 #print(rozsah) cat("v_t:") cat("\n") for (i in 1:n) {cat(vt[i]) cat("\n")} cat("E_f:") cat("\n") for (i in 1:n) {cat(Ef[i]) cat("\n")} pmv<-(max(vd)-min(vd))/2/sqrt(2) x1<- (vd-min(vd))/pmv-sqrt(2) pmP<-(max(Ps)-min(Ps))/2/sqrt(2) x2<- (Ps-min(Ps))/pmP-sqrt(2) pmvs<-(max(vs)-min(vs))/2/sqrt(2) xv<- (vs-min(vs))/pmvs - sqrt(2) rozsah2<-matrix(0,3,3) #rozsah2[1,1:2]<-(rozsah[1,1:2]-min(U))/pmu-sqrt(2) rozsah2[2,1:2]<-(rozsah[2,1:2]-min(vd))/pmv-sqrt(2) rozsah2[3,1:2]<-(rozsah[3,1:2]-min(Ps))/pmP-sqrt(2) rozsah2[,3]<-rozsah2[,1]+(rozsah2[,2]-rozsah2[,1])/2 x12<-x1^2 x22<-x2^2 x1x2<-x1*x2 vysl<-summary(lm(Ef ~ x1+ x2+x12+ x22+x1x2)) print(vysl) pm<-c("v_d","P_s","v_d^2","P_s^2","v_d*P_s") cat("E=") if (vysl$coef[1,4]<0.05) cat(vysl$coef[1,1]) for (i in 1:5) if (vysl$coef[i+1,4]<0.05) cat(ifelse(vysl$coef[i+1,1]>0,"+",""),vysl$coef[i+1,1],pm[i]) cat("\n") a<--vysl$coef[,1] #vysl2<-nlminb(c(rozsah[2:3,4]),fun2,lo=c(rozsah[2:3,1]),up=c(rozsah[2:3,2]),a=a) vysl2<-nlminb(c(rozsah2[2:3,3]),fun2,lo=c(rozsah2[2:3,1]),up=c(rozsah2[2:3,2]),a=a) opt<-vysl2$par #opt[1]<-(opt[1]+sqrt(2))*pmu+min(U) opt[1]<-(opt[1]+sqrt(2))*pmv+min(vd) opt[2]<-(opt[2]+sqrt(2))*pmP+min(Ps) en<--vysl2$obj #if(nap<0) nap<-opt[1] cat("\n") cat("Optim�ln� �e�en�:","\n") #en<--100000 pocet<-pocet+1 data2<-matrix(0,3,pocet) efe<-matrix(0,pocet,pocet) for (i in 2:2) data2[i,]<-seq(rozsah[i,1],rozsah[i,2],by=rozsah[i,3]) pmdata<-seq(vs1,vs2,by=vs3) data2[3,]<-kof*sort(data2[2,],decreasing = TRUE)/pmdata #for (i in 2:3) data2[i,]<-seq(rozsah[i,1],rozsah[i,2],by=rozsah[i,3]) #kde<-expand.grid(x=data2[2,], y=data2[3,]) kde<-expand.grid(x=(data2[2,]-min(vd))/pmv-sqrt(2), y= (data2[3,]-min(Ps))/pmP-sqrt(2)) xxx<-as.matrix(cbind(kde,kde[,1]^2,kde[,2]^2,kde[,1]*kde[,2])) efe<-cbind(rep(1,length(xxx[,1])),xxx)%*%vysl$coef[,1] #en<-max(efe) #jj<-which.max(efe) #opt[1]<-xxx[jj,1] #opt[2]<-xxx[jj,2] #opt[3]<-xxx[jj,3] y<-seq(vs1,vs2,by=vs3) #y<-kof*data2[2,]/data2[3,] grid<-expand.grid(x=data2[2,], y=y) grid$z<-efe cat("E=",en,"\n") for (i in 1:2) cat(pm[i],"=",opt[i],"\n") cat("v_s","=",kof*opt[1]/opt[2]) cat("\n") p1<-contourplot(z~y*x, grid, cuts = vrs, , xlab="vs", ylab="vd", region=T, main=paste("Efektivita E ",sep="")) #p2<-lpoints(vs,vd) plot(p1) #plot(p2) } else if (p==4) { data<-matrix(scan(file), byrow=T, ncol=6) if(kon<0) kon<-length(data[,1]) data<-data[poc:kon,] U<-data[,1] vd<-data[,2] vs<-data[,3] v<-data[,4] z<-data[,5] ctv<-data[,6] n<-length(vd) Ps<-kof*vd/vs vt<-1:n for (i in 1:n) vt[i]<-uniroot(funHu, low = -1000, up = 1000, tol = 0.01, a=Ps[i], b=z[i])$root Ef<-z/vt*(v-z)/(vt-z) rozsah<-matrix(0,5,4) x1<-U x2<-vd x3<-Ps x4<-ctv odp<-readline("Chce� nastavit rozsahy veli�in (stiskni a v p��pad� ano) ") if(odp=="a") { rozsah[1,1]<-as.real(readline("Nap�t� od ")) rozsah[1,2]<-as.real(readline(" do ")) rozsah[2,1]<-as.real(readline("v_d od ")) rozsah[2,2]<-as.real(readline(" do ")) rozsah[3,1]<-as.real(readline("v_s od ")) rozsah[3,2]<-as.real(readline(" do ")) rozsah[3,]<-kof*rozsah[2,]/rozsah[3,] } else {rozsah[1,1]<-min(x1) rozsah[1,2]<-max(x1) rozsah[2,1]<-min(x2) rozsah[2,2]<-max(x2) rozsah[3,1]<-min(x3) rozsah[3,2]<-max(x3) } rozsah[4,1]<-min(x4) rozsah[4,2]<-max(x4) rozsah[5,1]<-min(Ef) rozsah[5,2]<-max(Ef) rozsah[,3]<-(rozsah[,2]-rozsah[,1])/pocet rozsah[,4]<-rozsah[,1]+(rozsah[,2]-rozsah[,1])/2 cat("v_t:") print(vt) x12<-x1^2 x22<-x2^2 x32<-x3^2 x42<-x4^2 x1x2<-x1*x2 x1x3<-x1*x3 x1x4<-x1*x4 x2x3<-x2*x3 x2x4<-x2*x4 x3x4<-x3*x4 vysl<-summary(lm(Ef ~ x1+ x2+x3+x4+x12+ x22+x32+x42+x1x2+x1x3+x1x4+x2x3+x2x4+x3x4)) print(vysl) pm<-c("U","v_d","P_s","par4","U^2","v_d^2","P_s^2","par4^2","v_d*U","U*P_s","U*par4", "v_d*P_s","v_d*par4","P_s*par4") cat("E=") if (vysl$coef[1,4]<0.05) cat(vysl$coef[1,1]) for (i in 1:14) if (vysl$coef[i+1,4]<0.05) cat(ifelse(vysl$coef[i+1,1]>0,"+",""),vysl$coef[i+1,1],pm[i]) cat("\n") a<--vysl$coef[,1] vysl2<-nlminb(c(rozsah[1:3,4]),fun4,lo=c(rozsah[1:3,1]),up=c(rozsah[1:3,2]),a=a) opt<-vysl2$par en<--vysl2$obj if(nap<0) nap<-opt[1] cat("\n") cat("Optim�ln� �e�en�:","\n") #en<--100000 pocet<-pocet+1 data2<-matrix(0,4,pocet) efe<-matrix(0,pocet,pocet) for (i in 2:4) data2[i,]<-seq(rozsah[i,1],rozsah[i,2],by=rozsah[i,3]) kde<-expand.grid(nap, x=data2[2,], y=data2[3,], z=data2[4,]) xxx<-as.matrix(cbind(kde,kde[,1]^2,kde[,2]^2,kde[,3]^2,kde[,4]^2,kde[,1]*kde[,2],kde[,1]*kde[,3],kde[,1]*kde[,4], kde[,3]*kde[,2],kde[,2]*kde[,4],kde[,4]*kde[,3])) efe<-cbind(rep(1,length(xxx[,1])),xxx)%*%vysl$coef[,1] #en<-max(efe) #jj<-which.max(efe) #opt[1]<-xxx[jj,1] #opt[2]<-xxx[jj,2] #opt[3]<-xxx[jj,3] y<-kof*data2[2,]/data2[3,] grid<-expand.grid(x=data2[2,], y=y) grid$z<-efe cat("E=",en,"\n") for (i in 1:4) cat(pm[i],"=",opt[i],"\n") cat("v_s","=",kof*opt[2]/opt[3]) cat("\n") p1<- contourplot(z~y*x, grid, cuts = 10, , xlab="vs", ylab="vd", region=T, main=paste("Efektivita E, U=",round(nap,1)," V",sep="")) p2<-lpoints(vs,vd) plot(p1) #plot(p2) } else cat("�patn� zad�n�") } analyza2<-function(file="c:\\Opt2.txt",nap=-1,poc=1,kon=-1,pocet=100,kof=1.04) { library(grDevices) library(lattice) options(warn=-5) p<-as.integer(readline("zadej po�et parametr� ")) ############ if(p==3) { data<-matrix(scan(file), byrow=T, ncol=5) if(kon<0) kon<-length(data[,1]) data<-data[poc:kon,] U<-data[,1] vd<-data[,2] vs<-data[,3] v<-data[,4] z<-data[,5] n<-length(vd) Ps<-kof*vd/vs vt<-1:n for (i in 1:n) vt[i]<-uniroot(funHu, low = -1000, up = 1000, tol = 0.01, a=Ps[i], b=z[i])$root Ef<-z/vt*(v-z)/(vt-z) rozsah<-matrix(0,4,4) x1<-U x2<-vd x3<-Ps odp<-readline("Chce� nastavit rozsahy veli�in (stiskni a v p��pad� ano) ") if(odp=="a") { rozsah[1,1]<-as.real(readline("Nap�t� od ")) rozsah[1,2]<-as.real(readline(" do ")) rozsah[2,1]<-as.real(readline("v_d od ")) rozsah[2,2]<-as.real(readline(" do ")) #rozsah[3,1]<-as.real(readline("v_s od ")) #rozsah[3,2]<-as.real(readline(" do ")) vs1<-as.real(readline("v_s od ")) vs2<-as.real(readline(" do ")) rozsah[3,2]<-kof*rozsah[2,2]/vs1 rozsah[3,1]<-kof*rozsah[2,1]/vs2 #rozsah[3,]<-kof*rozsah[2,]/rozsah[3,] } else {rozsah[1,1]<-min(x1) rozsah[1,2]<-max(x1) rozsah[2,1]<-min(x2) rozsah[2,2]<-max(x2) vs1<-min(vs) vs2<-max(vs) rozsah[3,1]<kof*min(x2)/vs2 rozsah[3,2]<-kof*max(x2)/vs1 } rozsah[4,1]<-min(Ef) rozsah[4,2]<-max(Ef) rozsah[,3]<-(rozsah[,2]-rozsah[,1])/pocet vs3<-(vs2-vs1)/pocet rozsah[,4]<-rozsah[,1]+(rozsah[,2]-rozsah[,1])/2 cat("v_t:") cat("\n") for (i in 1:n) {cat(vt[i]) cat("\n")} cat("E_f:") cat("\n") for (i in 1:n) {cat(Ef[i]) cat("\n")} pmu<-(max(U)-min(U))/2/sqrt(3) x1<- (U-min(U))/pmu-sqrt(3) pmv<-(max(vd)-min(vd))/2/sqrt(3) x2<- (vd-min(vd))/pmv-sqrt(3) pmP<-(max(Ps)-min(Ps))/2/sqrt(3) x3<- (Ps-min(Ps))/pmP-sqrt(3) pmvs<-(max(vs)-min(vs))/2/sqrt(3) xv<- (vs-min(vs))/pmvs - sqrt(3) rozsah2<-matrix(0,3,3) rozsah2[1,1:2]<-(rozsah[1,1:2]-min(U))/pmu-sqrt(3) rozsah2[2,1:2]<-(rozsah[2,1:2]-min(vd))/pmv-sqrt(3) rozsah2[3,1:2]<-(rozsah[3,1:2]-min(Ps))/pmP-sqrt(3) rozsah2[,3]<-rozsah2[,1]+(rozsah2[,2]-rozsah2[,1])/2 x12<-x1^2 x22<-x2^2 x32<-x3^2 x1x2<-x1*x2 x1x3<-x1*x3 x2x3<-x2*x3 vysl<-summary(lm(Ef ~ x1+ x2+x3+x12+ x22+x32+x1x2+x1x3+x2x3)) print(vysl) pm<-c("U","v_d","P_s","U^2","v_d^2","P_s^2","v_d*U","U*P_s","v_d*P_s") cat("E=") if (vysl$coef[1,4]<0.05) cat(vysl$coef[1,1]) for (i in 1:9) if (vysl$coef[i+1,4]<0.05) cat(ifelse(vysl$coef[i+1,1]>0,"+",""),vysl$coef[i+1,1],pm[i]) cat("\n") a<--vysl$coef[,1] #vysl2<-nlminb(c(rozsah[1:3,4]),fun3,lo=c(rozsah[1:3,1]),up=c(rozsah[1:3,2]),a=a) vysl2<-nlminb(c(rozsah2[1:3,3]),fun3,lo=c(rozsah2[1:3,1]),up=c(rozsah2[1:3,2]),a=a) opt<-vysl2$par opt[1]<-(opt[1]+sqrt(3))*pmu+min(U) opt[2]<-(opt[2]+sqrt(3))*pmv+min(vd) opt[3]<-(opt[3]+sqrt(3))*pmP+min(Ps) en<--vysl2$obj if(nap<0) nap<-opt[1] nap1<- (nap-min(U))/pmu-sqrt(3) cat("\n") cat("Optim�ln� �e�en�:","\n") #en<--100000 pocet<-pocet+1 data2<-matrix(0,3,pocet) efe<-matrix(0,pocet,pocet) for (i in 2:2) data2[i,]<-seq(rozsah[i,1],rozsah[i,2],by=rozsah[i,3]) pmdata<-seq(vs1,vs2,by=vs3) data2[3,]<-kof*sort(data2[2,],decreasing = TRUE)/pmdata kde<-expand.grid(nap1, x=(data2[2,]-min(vd))/pmv-sqrt(3), y= (data2[3,]-min(Ps))/pmP-sqrt(3)) #kde<-expand.grid(nap, x=data2[2,], y=data2[3,]) xxx<-as.matrix(cbind(kde,kde[,1]^2,kde[,2]^2,kde[,3]^2,kde[,1]*kde[,2],kde[,1]*kde[,3],kde[,3]*kde[,2])) efe<-cbind(rep(1,length(xxx[,1])),xxx)%*%vysl$coef[,1] #en<-max(efe) #jj<-which.max(efe) #opt[1]<-xxx[jj,1] #opt[2]<-xxx[jj,2] #opt[3]<-xxx[jj,3] y<-seq(vs1,vs2,by=vs3) #y<-kof*data2[2,]/data2[3,] grid<-expand.grid(x=data2[2,], y=y) grid$z<-efe cat("E=",en,"\n") for (i in 1:3) cat(pm[i],"=",opt[i],"\n") cat("v_s","=",kof*opt[2]/opt[3]) cat("\n") wireframe(z~y*x, grid, xlab="vs", ylab="vd", zlab="E", main=paste("Efektivita E, U=",nap," V",sep=""), drape = T) } ################################ else if(p==2) { data<-matrix(scan(file), byrow=T, ncol=4) if(kon<0) kon<-length(data[,1]) data<-data[poc:kon,] #U<-data[,1] vd<-data[,1] vs<-data[,2] v<-data[,3] z<-data[,4] n<-length(vd) Ps<-kof*vd/vs vt<-1:n for (i in 1:n) vt[i]<-uniroot(funHu, low = -1000, up = 1000, tol = 0.01, a=Ps[i], b=z[i])$root Ef<-z/vt*(v-z)/(vt-z) rozsah<-matrix(0,4,4) #x1<-U x1<-vd x2<-Ps odp<-readline("Chce� nastavit rozsahy veli�in (stiskni a v p��pad� ano) ") if(odp=="a") { # rozsah[1,1]<-as.real(readline("Nap�t� od ")) # rozsah[1,2]<-as.real(readline(" do ")) rozsah[2,1]<-as.real(readline("v_d od ")) rozsah[2,2]<-as.real(readline(" do ")) vs1<-as.real(readline("v_s od ")) vs2<-as.real(readline(" do ")) rozsah[3,2]<-kof*rozsah[2,2]/vs1 rozsah[3,1]<-kof*rozsah[2,1]/vs2 } else { #rozsah[1,1]<-min(x1) #rozsah[1,2]<-max(x1) rozsah[2,1]<-min(x1) rozsah[2,2]<-max(x1) rozsah[3,1]<-min(x2) rozsah[3,2]<-max(x2) vs1<-min(vs) vs2<-max(vs) rozsah[3,1]<kof*min(x2)/vs2 rozsah[3,2]<-kof*max(x2)/vs1 } rozsah[4,1]<-min(Ef) rozsah[4,2]<-max(Ef) rozsah[,3]<-(rozsah[,2]-rozsah[,1])/pocet vs3<-(vs2-vs1)/pocet rozsah[,4]<-rozsah[,1]+(rozsah[,2]-rozsah[,1])/2 #print(rozsah) cat("v_t:") cat("\n") for (i in 1:n) {cat(vt[i]) cat("\n")} cat("E_f:") cat("\n") for (i in 1:n) {cat(Ef[i]) cat("\n")} pmv<-(max(vd)-min(vd))/2/sqrt(2) x1<- (vd-min(vd))/pmv-sqrt(2) pmP<-(max(Ps)-min(Ps))/2/sqrt(2) x2<- (Ps-min(Ps))/pmP-sqrt(2) pmvs<-(max(vs)-min(vs))/2/sqrt(2) xv<- (vs-min(vs))/pmvs - sqrt(2) rozsah2<-matrix(0,3,3) #rozsah2[1,1:2]<-(rozsah[1,1:2]-min(U))/pmu-sqrt(2) rozsah2[2,1:2]<-(rozsah[2,1:2]-min(vd))/pmv-sqrt(2) rozsah2[3,1:2]<-(rozsah[3,1:2]-min(Ps))/pmP-sqrt(2) rozsah2[,3]<-rozsah2[,1]+(rozsah2[,2]-rozsah2[,1])/2 x12<-x1^2 x22<-x2^2 x1x2<-x1*x2 vysl<-summary(lm(Ef ~ x1+ x2+x12+ x22+x1x2)) print(vysl) pm<-c("v_d","P_s","v_d^2","P_s^2","v_d*P_s") cat("E=") if (vysl$coef[1,4]<0.05) cat(vysl$coef[1,1]) for (i in 1:5) if (vysl$coef[i+1,4]<0.05) cat(ifelse(vysl$coef[i+1,1]>0,"+",""),vysl$coef[i+1,1],pm[i]) cat("\n") a<--vysl$coef[,1] #vysl2<-nlminb(c(rozsah[2:3,4]),fun2,lo=c(rozsah[2:3,1]),up=c(rozsah[2:3,2]),a=a) vysl2<-nlminb(c(rozsah2[2:3,3]),fun2,lo=c(rozsah2[2:3,1]),up=c(rozsah2[2:3,2]),a=a) opt<-vysl2$par #opt[1]<-(opt[1]+sqrt(2))*pmu+min(U) opt[1]<-(opt[1]+sqrt(2))*pmv+min(vd) opt[2]<-(opt[2]+sqrt(2))*pmP+min(Ps) en<--vysl2$obj #if(nap<0) nap<-opt[1] cat("\n") cat("Optim�ln� �e�en�:","\n") #en<--100000 pocet<-pocet+1 data2<-matrix(0,3,pocet) efe<-matrix(0,pocet,pocet) for (i in 2:2) data2[i,]<-seq(rozsah[i,1],rozsah[i,2],by=rozsah[i,3]) pmdata<-seq(vs1,vs2,by=vs3) data2[3,]<-kof*sort(data2[2,],decreasing = TRUE)/pmdata #for (i in 2:3) data2[i,]<-seq(rozsah[i,1],rozsah[i,2],by=rozsah[i,3]) #kde<-expand.grid(x=data2[2,], y=data2[3,]) kde<-expand.grid(x=(data2[2,]-min(vd))/pmv-sqrt(2), y= (data2[3,]-min(Ps))/pmP-sqrt(2)) xxx<-as.matrix(cbind(kde,kde[,1]^2,kde[,2]^2,kde[,1]*kde[,2])) efe<-cbind(rep(1,length(xxx[,1])),xxx)%*%vysl$coef[,1] #en<-max(efe) #jj<-which.max(efe) #opt[1]<-xxx[jj,1] #opt[2]<-xxx[jj,2] #opt[3]<-xxx[jj,3] y<-seq(vs1,vs2,by=vs3) #y<-kof*data2[2,]/data2[3,] grid<-expand.grid(x=data2[2,], y=y) grid$z<-efe cat("E=",en,"\n") for (i in 1:2) cat(pm[i],"=",opt[i],"\n") cat("v_s","=",kof*opt[1]/opt[2]) cat("\n") wireframe(z~y*x, grid, xlab="vs", ylab="vd", zlab="E", main=paste("Efektivita E",sep=""), drape = T) } else if (p==4) { data<-matrix(scan(file), byrow=T, ncol=6) if(kon<0) kon<-length(data[,1]) data<-data[poc:kon,] U<-data[,1] vd<-data[,2] vs<-data[,3] v<-data[,4] z<-data[,5] ctv<-data[,6] n<-length(vd) Ps<-kof*vd/vs vt<-1:n for (i in 1:n) vt[i]<-uniroot(funHu, low = -1000, up = 1000, tol = 0.01, a=Ps[i], b=z[i])$root Ef<-z/vt*(v-z)/(vt-z) rozsah<-matrix(0,5,4) x1<-U x2<-vd x3<-Ps x4<-ctv odp<-readline("Chce� nastavit rozsahy veli�in (stiskni a v p��pad� ano) ") if(odp=="a") { rozsah[1,1]<-as.real(readline("Nap�t� od ")) rozsah[1,2]<-as.real(readline(" do ")) rozsah[2,1]<-as.real(readline("v_d od ")) rozsah[2,2]<-as.real(readline(" do ")) rozsah[3,1]<-as.real(readline("v_s od ")) rozsah[3,2]<-as.real(readline(" do ")) rozsah[3,]<-kof*rozsah[2,]/rozsah[3,] } else {rozsah[1,1]<-min(x1) rozsah[1,2]<-max(x1) rozsah[2,1]<-min(x2) rozsah[2,2]<-max(x2) rozsah[3,1]<-min(x3) rozsah[3,2]<-max(x3) } rozsah[4,1]<-min(x4) rozsah[4,2]<-max(x4) rozsah[5,1]<-min(Ef) rozsah[5,2]<-max(Ef) rozsah[,3]<-(rozsah[,2]-rozsah[,1])/pocet rozsah[,4]<-rozsah[,1]+(rozsah[,2]-rozsah[,1])/2 cat("v_t:") print(vt) x12<-x1^2 x22<-x2^2 x32<-x3^2 x42<-x4^2 x1x2<-x1*x2 x1x3<-x1*x3 x1x4<-x1*x4 x2x3<-x2*x3 x2x4<-x2*x4 x3x4<-x3*x4 vysl<-summary(lm(Ef ~ x1+ x2+x3+x4+x12+ x22+x32+x42+x1x2+x1x3+x1x4+x2x3+x2x4+x3x4)) print(vysl) pm<-c("U","v_d","P_s","par4","U^2","v_d^2","P_s^2","par4^2","v_d*U","U*P_s","U*par4", "v_d*P_s","v_d*par4","P_s*par4") cat("E=") if (vysl$coef[1,4]<0.05) cat(vysl$coef[1,1]) for (i in 1:14) if (vysl$coef[i+1,4]<0.05) cat(ifelse(vysl$coef[i+1,1]>0,"+",""),vysl$coef[i+1,1],pm[i]) cat("\n") a<--vysl$coef[,1] vysl2<-nlminb(c(rozsah[1:3,4]),fun4,lo=c(rozsah[1:3,1]),up=c(rozsah[1:3,2]),a=a) opt<-vysl2$par en<--vysl2$obj if(nap<0) nap<-opt[1] cat("\n") cat("Optim�ln� �e�en�:","\n") #en<--100000 pocet<-pocet+1 data2<-matrix(0,4,pocet) efe<-matrix(0,pocet,pocet) for (i in 2:4) data2[i,]<-seq(rozsah[i,1],rozsah[i,2],by=rozsah[i,3]) kde<-expand.grid(nap, x=data2[2,], y=data2[3,], z=data2[4,]) xxx<-as.matrix(cbind(kde,kde[,1]^2,kde[,2]^2,kde[,3]^2,kde[,4]^2,kde[,1]*kde[,2],kde[,1]*kde[,3],kde[,1]*kde[,4], kde[,3]*kde[,2],kde[,2]*kde[,4],kde[,4]*kde[,3])) efe<-cbind(rep(1,length(xxx[,1])),xxx)%*%vysl$coef[,1] #en<-max(efe) #jj<-which.max(efe) #opt[1]<-xxx[jj,1] #opt[2]<-xxx[jj,2] #opt[3]<-xxx[jj,3] y<-kof*data2[2,]/data2[3,] grid<-expand.grid(x=data2[2,], y=y) grid$z<-efe cat("E=",en,"\n") for (i in 1:4) cat(pm[i],"=",opt[i],"\n") cat("v_s","=",kof*opt[2]/opt[3]) cat("\n") wireframe(z~y*x, grid, xlab="vs", ylab="vd", zlab="E", main=paste("Efektivita E, U=",nap," V",sep=""), drape = T) } else cat("�patn� zad�n�") } analyza3<-function(file="c:\\Opt2.txt",poc=1,kon=-1,kof=1.04) { library(grDevices) library(lattice) options(warn=-5) p<-as.integer(readline("zadej po�et parametr� ")) if(p==3) { data<-matrix(scan(file), byrow=T, ncol=5) if(kon<0) kon<-length(data[,1]) data<-data[poc:kon,] vd<-data[,2] vs<-data[,3] z<-data[,5] n<-length(vd) Ps<-kof*vd/vs} else if(p==2) { data<-matrix(scan(file), byrow=T, ncol=4) if(kon<0) kon<-length(data[,1]) data<-data[poc:kon,] vd<-data[,1] vs<-data[,2] z<-data[,4] n<-length(vd) Ps<-kof*vd/vs } else if (p==4) { data<-matrix(scan(file), byrow=T, ncol=6) if(kon<0) kon<-length(data[,1]) data<-data[poc:kon,] vd<-data[,2] vs<-data[,3] z<-data[,5] n<-length(vd) Ps<-kof*vd/vs } else cat("�patn� zad�n�") if (p==2 | p==3 | p==4){ odp<-readline("Chce� nastavit rozsahy veli�in (stiskni a v p��pad� ano) ") if(odp=="a") { zd<-as.real(readline("Z�var od ")) zh<-as.real(readline(" do ")) Pd<-as.real(readline("Plocha od ")) Ph<-as.real(readline(" do ")) } else {zd<-min(z)-0.1 zh<-max(z)+0.1 Pd<-min(round(Ps,1))-0.2 Ph<-max(round(Ps,1))+0.2 } plot(Ps~z,pch=4,xlab="z�var",ylab="Plocha",axes=FALSE,xlim=c(zd,zh),ylim=c(Pd,Ph)) for (i in 1:n) text(z[i]+0.03,Ps[i]-0.03,i) axis(1, seq(zd,zh,by=0.1)) axis(2, seq(trunc(Pd),ceiling(Ph),by=0.5),las=1) box() mtext("efektivn� nosn� velikost vt",side=3,col="blue",line=0.5) mtext("efektivita z�varu Ez",side=4,col="green",line=0.5) grid(lwd = 2) zz<-seq(zd,zh,by=0.01) for (i in seq(4.0,14.0,by=0.1)){ pm<-i*(i-zz)^2/sqrt(i^2-zz^2) lines(pm~zz,col="blue") } for (i in seq(4.6,14.0,by=0.2)) {pzz<-uniroot(funHu2, low = i-6, up = i-2, tol = 0.01, a=Ph, b=i)$root text(pzz,Ph,i,col="blue")} for (i in seq(0.3,0.8,by=0.01)){ vtt<-zz/i pm2<-vtt*(vtt-zz)^2/sqrt(vtt^2-zz^2) lines(pm2~zz,col="green") } for (i in seq(0.3,0.8,by=0.03)){ pzz<-uniroot(funHu3, low = 0.5, up = 14.25, tol = 0.01, a=Pd, b=i)$root text(pzz,Pd,i,col="green") } } } uroven<-function(dh, hh) { jedn<-(hh-dh)/2/sqrt(3) pm<-rep(0,5) pm[1]<-dh pm[5]<-hh pm[3]<-(dh+hh)/2 pm[2]<-pm[3]-jedn pm[4]<-pm[3]+jedn pm } funHu<- function (x,a,b ) a-x*(x-b)^2/sqrt(x^2-b^2) funHu2<- function (x,a,b ) a-b*(b-x)^2/sqrt(b^2-x^2) funHu3<- function (x,a,b ) a-x/b*(x/b-x)^2/sqrt((x/b)^2-x^2) fun3<-function(x,a) { x1<-x[1] x2<-x[2] x3<-x[3] a[1]+a[2]*x1+ a[3]*x2+a[4]*x3+a[5]*x1^2+ a[6]*x2^2+a[7]*x3^2+a[8]*x1*x2+a[9]*x1*x3+a[10]*x2*x3 } fun4<-function(x,a) { x1<-x[1] x2<-x[2] x3<-x[3] x4<-x[4] a[1]+a[2]*x1+ a[3]*x2+a[4]*x3+a[5]*x4+a[6]*x1^2+ a[7]*x2^2+a[8]*x3^2+a[9]*x4^2+a[10]*x1*x2+a[11]*x1*x3+ a[12]*x1*x4+a[13]*x2*x3+a[14]*x2*x4+a[15]*x3*x4 } fun2<-function(x,a) { x1<-x[1] x2<-x[2] a[1]+a[2]*x1+ a[3]*x2+a[4]*x1^2+ a[5]*x2^2+a[6]*x1*x2 } <SPAN style="DISPLAY: none" data-cke-bookmark="1"> </SPAN>