版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、VB解一元二次方程配方法我也是一个vb的超级菜鸟,但是我运用我所学的数学知识,编辑了一个解一元二次方程的配方法过程的这么一个程序。我是自己原创,至于是不是首创就不知道了。(很多网上直接出答案的都是运用公式法计算的,那么我就想写个有过程的程序,完爆数学老师)好了,废话不说多,现在先上测试图,有图有真相嘛。这个程序有几个重点(后面源码都有注释)1、 a值要变为正数,否则将无法运行2、 开不尽的数要用根号表示,不会像2=1.414这么多小数3、 分母有理化,倒数第二步的分母不能为根号(标准)4、 移项时的符号注意变化。下面是界面介绍:下面直接上源码了,有注释自己可以理解。Dim a$ ,b$,c$,
2、d$,e$,f$,g$,h$Dim jj!Dim ii!Dim pp!Private Sub Command1_Click()a = Text1.Textb = Text2.Textc = Text3.Textd = Text4.TextIf a = 1 Then 第一步,先列出原式Label3.Caption = x2End IfIf a = -1 ThenLabel3.Caption = -x2End IfIf Not a = 1 And Not a = -1 ThenLabel3.Caption = a & x2End IfIf b 0 ThenLabel3.Caption = Labe
3、l3.Caption & + & bElseLabel3.Caption = Label3.Caption & bEnd IfIf c 0 ThenLabel3.Caption = Label3.Caption & x+ & c & = & dElseLabel3.Caption = Label3.Caption & x & c & = & dEnd IfIf a 0 Then 当a为负数时,每个项同时乘以-1a = -ab = -bc = -cd = -dEnd Ifc = c - d 移项,将右边移向左边If a = 0 Then 判断有无解Label3.Caption = Label3.
4、Caption & vbCrLf & 原方程无解End IfIf (b 2) - (4 * a * c) 0 ThenLabel3.Caption = Label3.Caption & + & bElseLabel3.Caption = Label3.Caption & bEnd IfIf c 0 ThenLabel3.Caption = Label3.Caption & x+ & c & =0ElseLabel3.Caption = Label3.Caption & x & c & =0End Ife = (b 2) / (4 * a) 算出适合配方的新c值f = e - c 新c值与原c值
5、的差,两边同时加差值If a = 1 Then 第三步,写出初步配方的结果Label3.Caption = Label3.Caption & vbCrLf & x2End IfIf a = -1 ThenLabel3.Caption = Label3.Caption & vbCrLf & -x2End IfIf Not a = 1 And Not a = -1 ThenLabel3.Caption = Label3.Caption & vbCrLf & a & x2End IfIf b 0 ThenLabel3.Caption = Label3.Caption & + & bElseLabel
6、3.Caption = Label3.Caption & bEnd IfIf e 0 ThenLabel3.Caption = Label3.Caption & x+ & e & = & fElseLabel3.Caption = Label3.Caption & x & e & = & fEnd Ifg = (-b + Sqr(b 2 - 4 * a * c) / (2 * a) 后台使用公式法计算h = (-b - Sqr(b 2 - 4 * a * c) / (2 * a)If g 0 And g 1 Then 给0 y 1的数前加个0g = 0 & gEnd IfIf g -1 The
7、ng = -gg = -0 & gEnd IfIf h 0 And h 1 Thenh = 0 & hEnd IfIf h -1 Thenh = -hh = -0 & hEnd Ifjj = Sqr(a)If a = 1 Then 第四步,运用完全平方公式进行配方Label3.Caption = Label3.Caption & vbCrLf & (xEnd IfIf a = -1 ThenLabel3.Caption = Label3.Caption & vbCrLf & (-xEnd IfIf Not a = 1 And Not a = -1 ThenIf Not Len(CStr(jj
8、- Fix(jj) 4 ThenLabel3.Caption = Label3.Caption & vbCrLf & ( & Sqr(a) & xEnd IfIf Len(CStr(jj - Fix(jj) 4 Then小数大于3位时用根号表示,不直接开方Label3.Caption = Label3.Caption & vbCrLf & ( & a & xEnd IfEnd If-第一层-ii = Sqr(e)If b 0 ThenIf Not Len(CStr(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & + & Sqr(e) &
9、 )2= & fEnd IfIf Len(CStr(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & + & & e & )2= & fEnd IfEnd IfIf b 4 ThenLabel3.Caption = Label3.Caption & - & Sqr(e) & )2= & fEnd IfIf Len(CStr(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & - & & e & )2= & fEnd IfEnd If-第二层-If a = 1 Then 第五步,两边同时
10、开根号Label3.Caption = Label3.Caption & vbCrLf & xEnd IfIf a = -1 ThenLabel3.Caption = Label3.Caption & vbCrLf & -xEnd IfIf Not a = 1 And Not a = -1 ThenIf Not Len(CStr(jj - Fix(jj) 4 ThenLabel3.Caption = Label3.Caption & vbCrLf & & Sqr(a) & xEnd IfIf Len(CStr(jj - Fix(jj) 4 ThenLabel3.Caption = Label3
11、.Caption & vbCrLf & & a & xEnd IfEnd IfIf b 0 ThenIf Not Len(CStr(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & + & Sqr(e) & =End IfIf Len(CStr(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & + & & e & =End IfEnd IfIf b 4 ThenLabel3.Caption = Label3.Caption & - & Sqr(e) & =End IfIf Len(C
12、Str(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & - & & e & =End IfEnd Ifpp = Sqr(f)If Not Len(CStr(pp - Fix(pp) 4 ThenLabel3.Caption = Label3.Caption & & Sqr(f)End IfIf Len(CStr(pp - Fix(pp) 4 ThenLabel3.Caption = Label3.Caption & & fEnd IfLabel3.Caption = Label3.Caption & vbCrLf & x= 第六步,移项
13、,x在左If Len(CStr(jj - Fix(jj) 4 Then 分母有理化(后补分母)Label3.Caption = Label3.Caption & & aEnd IfIf a = 1 ThenIf Not Len(CStr(pp - Fix(pp) 4 ThenLabel3.Caption = Label3.Caption & & Sqr(f)End IfIf Len(CStr(pp - Fix(pp) 4 ThenLabel3.Caption = Label3.Caption & & fEnd IfIf b 0 ThenIf Not Len(CStr(ii - Fix(ii)
14、4 ThenLabel3.Caption = Label3.Caption & - & Sqr(e)End IfIf Len(CStr(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & - & & eEnd IfEnd IfIf b 4 ThenLabel3.Caption = Label3.Caption & + & Sqr(e)End IfIf Len(CStr(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & + & & eEnd IfEnd IfEnd If-第一层-If N
15、ot a = 1 ThenIf Not Len(CStr(pp - Fix(pp) 4 ThenLabel3.Caption = Label3.Caption & ( & Sqr(f)End IfIf Len(CStr(pp - Fix(pp) 4 ThenLabel3.Caption = Label3.Caption & ( & fEnd IfIf b 0 ThenIf Not Len(CStr(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & - & Sqr(e) & )/End IfIf Len(CStr(ii - Fix(ii)
16、4 ThenLabel3.Caption = Label3.Caption & - & & e & )/End IfEnd IfIf b 4 ThenLabel3.Caption = Label3.Caption & + & Sqr(e) & )/End IfIf Len(CStr(ii - Fix(ii) 4 ThenLabel3.Caption = Label3.Caption & + & & e & )/End IfEnd IfIf Not Len(CStr(jj - Fix(jj) 4 ThenLabel3.Caption = Label3.Caption & Sqr(a)End If
17、If Len(CStr(jj - Fix(jj) 4 ThenLabel3.Caption = Label3.Caption & aEnd IfEnd IfLabel3.Caption = Label3.Caption & vbCrLf & x= & g & 或x= & h 第七步,得解End SubPrivate Sub Command2_Click()Text1.Text = Text2.Text = Text3.Text = Text4.Text = Label3.Caption = 解题区域End SubPrivate Sub Command3_Click()a = Text1.Tex
18、tb = Text2.Textc = Text3.Textd = Text4.Textc = c - dLabel6.Visible = TrueLabel7.Visible = TrueLabel8.Visible = TrueLabel9.Visible = TrueLine1.Visible = TrueLine2.Visible = TrueLabel5.Caption = a= & a & ,b= & b & ,c= & c 第一步,列出a、b、c的值(格式严谨)Label5.Caption = Label5.Caption & vbCrLf & =b2-4ac= & (b 2) - (4 * a * c) 第二步,算出变量b2-4ac的值If (b 2) - (4 * a * c) 0 Then 第三步,判断方程有无解Label5.Caption = Label5.Caption & vbCrLf & b2-4ac 0 ThenLabel7.Caption = - & b & & (b 2) - (4 * a * c) 第四步,写分子
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年注塑成型仿真分析项目可行性研究报告
- 社区戒毒和社区康复培训课件
- 2026年节能降碳改造贷项目投资计划书
- 2026年智能水下灯项目可行性研究报告
- 2026年生物类似药项目投资计划书
- 2026年隐私计算安全融合项目评估报告
- 电路知识第六十六讲
- 社保培训知识
- 教职工福利待遇制度
- 教师职称评定工作制度
- 食品加工厂乳制品设备安装方案
- 2025至2030中国芳纶纤维行业发展分析及市场发展趋势分析与未来投资战略咨询研究报告
- 尾牙宴活动策划方案(3篇)
- 鲁教版(2024)五四制英语七年级上册全册综合复习默写 (含答案)
- 生蚝课件教学课件
- 组塔架线安全培训
- 化疗神经毒性反应护理
- 2025年度运营数据支及决策对工作总结
- 2025年《外科学基础》知识考试题库及答案解析
- 2025年湖南省公务员录用考试《申论》真题(县乡卷)及答案解析
- 粉尘清扫安全管理制度完整版
评论
0/150
提交评论