楼主是不是参考的别人的程序,initializega这个子函数在你的电脑中并不存在
可能是matlab版本问题,matlab7以上的版本中没有initializega函数了,全都集合到gaoptimset函数中。
旧版本中的initializega函数:
function [pop] = initializega(num, bounds, evalFN,evalOps,options)
% function [pop]=initializega(populationSize, variableBounds,evalFN,
% evalOps,options)
% initializega creates a matrix of random numbers with
% a number of rows equal to the populationSize and a number
% columns equal to the number of rows in bounds plus 1 for
% the f(x) value which is found by applying the evalFN
% This is used by the ga to create the population if it
% is not supplied
%
% pop - the initial, evaluated, random population
% populatoinSize - the size of the population, ie the number to create
% variableBounds - a matrix which contains the bounds of each variable, ie
% [var1_high var1_low; var2_high var2_low; ]
% evalFN - the evaluation fn, usually the name of the m file for
% evaluation
% evalOps - any options to be passed to the eval function defaults []
% options - options to the initialize function, ie
% [type prec] where eps is the epsilon value
% and the second option is 1 for float and 0 for binary,
% prec is the precision of the variables defaults [1e-6 1]
% Binary and Real-Valued Simulation Evolution for Matlab GAOT V2
% Copyright (C) 1998 CR Houck, JA Joines, MG Kay
%
% CR Houck, JJoines, and MKay A genetic algorithm for function
% optimization: A Matlab implementation ACM Transactions on Mathmatical
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 1, or (at your option)
% any later version
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the
% GNU General Public License for more details A copy of the GNU
% General Public License can be obtained from the
% Free Software Foundation, Inc, 675 Mass Ave, Cambridge, MA 02139, USA
if nargin<5
options=[1e-6 1];
end
if nargin<4
evalOps=[];
end
if any(evalFN<48) %Not a m file
if options(2)==1 %Float GA
estr=['x=pop(i,1); pop(i,xZomeLength)=', evalFN ';'];
else %Binary GA
estr=['x=b2f(pop(i,:),bounds,bits); pop(i,xZomeLength)=', evalFN ';'];
end
else %A m file
if options(2)==1 %Float GA
estr=['[ pop(i,:) pop(i,xZomeLength)]=' evalFN '(pop(i,:),[0 evalOps]);'];
else %Binary GA
estr=['x=b2f(pop(i,:),bounds,bits);[x v]=' evalFN
'(x,[0 evalOps]); pop(i,:)=[f2b(x,bounds,bits) v];'];
end
end
numVars = size(bounds,1); %Number of variables
rng = (bounds(:,2)-bounds(:,1))'; %The variable ranges'
if options(2)==1 %Float GA
xZomeLength = numVars+1; %Length of string is numVar + fit
pop = zeros(num,xZomeLength); %Allocate the new population
pop(:,1:numVars)=(ones(num,1)rng)(rand(num,numVars))+
(ones(num,1)bounds(:,1)');
else %Binary GA
bits=calcbits(bounds,options(1));
xZomeLength = sum(bits)+1; %Length of string is numVar + fit
pop = round(rand(num,sum(bits)+1));
end
for i=1:num
eval(estr);
end
Systemoutprint("请输入折扣:");
zeko=scannernextDouble();
zekoh=zekouqianzeko;
你之前只是将单个商品的账单打印出来了,但是没有将账单总值加在一起,因此zekouqian变量还是o,你需要在将代码顺序改一下
package text1;
import javautilScanner;
public class nidechao1 {
public static void main(String args[]){
double DTVqian=30; //T恤单价
double Dpaiqian=248; //网球拍单价
double Dxieqian=150; //网球鞋单价
double STVqian=0; //T恤总价
double Sxieqian=0; //网球鞋总价
double Spaiqian=0; //网球拍总价
int tvnum=0; //T恤数量
int painum=0; //网球拍数量
int xienum=0; // 网球鞋数量
double zekouqian=0;// 折扣前总价
double zeko=00; //折扣后总价
double zekoh=0; //折扣
double fk=0; //付款
double zl=0; //找零
Scanner scanner =new Scanner(Systemin);
Systemoutprintln("请输入购买T恤数量:");
tvnum = scannernextInt();
Systemoutprintln("请输入购买网球拍数量:");
painum=scannernextInt();
Systemoutprintln("请输入购买网球鞋数量:");
xienum=scannernextInt();
STVqian=tvnumDTVqian;
Spaiqian=painumDpaiqian;
Sxieqian=xienumDxieqian;
zekouqian=STVqian+Spaiqian+Sxieqian;
Systemoutprintln("消费单据");
Systemoutprintln("消费单");
Systemoutprintln("购买商品\t单价\t数量\t金额");
Systemoutprintln("T恤:\t"+DTVqian+"\t"+tvnum+"\t"+STVqian);
Systemoutprintln("网球拍:\t"+Dpaiqian+"\t"+painum+"\t"+Spaiqian);
Systemoutprintln("网球鞋:\t"+Dxieqian+"\t"+xienum+"\t"+Sxieqian);
Systemoutprint("请输入折扣:");
zeko=scannernextDouble();
zekoh=zekouqianzeko;
Systemoutprintln("总金额:"+ zekoh);
Systemoutprintln("付款:");
fk=scannernextDouble();
Systemoutprintln("找零:"+(fk-zekoh));
}
}
#include "stdafxh"
#include "iostream"
#include "mathh"
using namespace std;
int _tmain(int argc, _TCHAR argv[])
{
double x = 11;
while(fabs(5xxx-3xx+2x-8)>0000001)
x = x - (5xxx-3xx+2x-8)/(15xx-6x+2);
cout<<"方程的解为"<<x<<endl;
system("pause");
return 0;
}
重点改动:
scanf("%lf,%lf",&x1,&x2);
#include <stdioh>
#include <mathh>
int main()
{ double calculate(double y1,double y2,double fy1,double fy2);
double x1,x2,fx1,fx2;
double a;
printf("enter x1 & x2:");
scanf("%lf,%lf",&x1,&x2);
fx1=(((x1+3)x1-8)x1+12)x1-10;
fx2=(((x2+3)x2-8)x2+12)x2-10;
printf("%f %f %f %f\n",x1,x2,fx1,fx2);
a=calculate(x1,x2,fx1,fx2);
printf("x=%lf\n",a);
return 0;
}
double calculate(double y1,double y2,double fy1,double fy2)
{ double fy0,y0;
double a;
y0=(y1+y2)/2;
fy0=(((y0+3)y0-8)y0+12)y0-10;
printf("%f ",y0);
if(fabs(fy0)>=1e-10)
{ if ((fy0fy1)<0)
{ y2=y0;
fy2=fy0;
}
else
{ y1=y0;
fy1=fy0;
}
a=calculate(y1,y2,fy1,fy2);
}
else
{ a=y0;
printf("%62f",a);
}
return(a);
}
1、直接用数转换到字符串的方法即可。sprintf(s,"%lf",a);s是字符数组,a是double。这样就把a写到s中了。
2、例程:
#include<stdioh>
#include<iostream>
using namespace std;
int main()
{
char s[12];
double a=123456789876;
sprintf(s,"%lf",a);
printf("%s",s);
return 0;
}
1、在打开的ie浏览器窗口右上方点击齿轮图标,选择“Internet选项”,如下图所示:
2、在打开的Internet选项窗口中,切换到安全栏,在安全选卡中点击“自定义级别”,如下图所示:
3、在“安全设置-Internet 区域”界面找到“Java 小程序脚本”、“活动脚本”,并将这两个选项都选择为“禁用”,然后点击确定,如下图所示:
// 根据直线方程的一般式Ax+By+C=0,点到直线的距离公式:d=(Ax0+By0+C)/sqrt(AA+BB)推断出垂足的计算公式
double da = y3-y2;
double db = x2-x3;
double dc = x3y2-x2y3;
dx = ( dbdbx1 - dadby1 - dadc ) / ( dada + dbdb );
dy = ( -dadbx1 + daday1 - dbdc ) / ( dada + dbdb );
double ea = y3-y1;
double eb = x1-x3;
double ec = x3y1-x1y3;
ex = ( ebebx2 - eaeby2 - eaec ) / ( eaea + ebeb );
ey = ( -eaebx2 + eaeay2 - ebec ) / ( eaea + ebeb );
double fa = y1-y2;
double fb = x2-x1;
double fc = x1y2-x2y1;
fx = ( fbfbx3 - fafby3 - fafc ) / ( fafa + fbfb );
fy = ( -fafbx3 + fafay3 - fbfc ) / ( fafa + fbfb );
cout << "顶点A至BC边的垂足D(" << dx << "," << dy << "),AD = " << AD << endl;
cout << "顶点B至AC边的垂足E(" << ex << "," << ey << "),BE = " << BE << endl;
cout << "顶点C至AB边的垂足F(" << fx << "," << fy << "),CF = " << CF << endl;
欢迎分享,转载请注明来源:品搜搜测评网