自定义函数求一元二次方程

自定义函数求一元二次方程(C语言) 题目: 求方程的根,用三个函数分别求当b^2-4ac大于0、等于0、和小于0时的根,并输出结果。从主函数输入a、b、c的值。 一般式:ax²+bx+c=0(a≠0) 其中a是二次项系数,b是一次项系数,c叫作常数项。 思路: 利用一元二次方程根的判别式可以判断方程的根的情况▲ = b² - 4ac 大于0和等于0两种计算的公式都为 而小于0时无实数根但有两个共轭复数,公式为 一元二次方程的根与根的判别式 有如下关系: ① 当 ▲ > 0 时,方程有两个不相等的实数根; ② 当 ▲ 阅读详情
题目描述

求方程y=ax2+bx+c的根,用三个函数分别求当b2−4ac大于0、等于0、和小于0时的根,并输出结果。从主函数输入a、b、c的值。

输入

a b c

输出

一元二次方程的俩个根 "x1=?x2=?"

样例输入
  1. 4 1 1
样例输出
  1. x1=-0.125+0.484i x2=-0.125-0.484i
import math
def fun1(a,b,c,n):
    x1=(-b+n**0.5)/(2*a)
    x2=(-b-n**0.5)/(2*a)
    print(f"{x1:.6f}{x2:.6f}")

def fun2(a,b):
    x=(-b)/(2*a)
    print(f"{x:.6f}{x:.6f}")
def fun3(a,b,c,n):
    shi = -1 * b/ (2 * a)
    xu = math.sqrt(-1 * n) / (2 * a)
    print(f'x1={shi:.3f}+{xu:.3f}i x2={shi:.3f}-{xu:.3f}i')

def main():
    a,b,c=map(int,input().split())
    n=b**2-4*a*c
    if n>0:
        fun1(a,b,c,n)

    if n==0:
        fun2(a,b)

    if n<0:
        fun3(a,b,c,n)

if __name__ == '__main__':
    main()

 

java【自定义函数求一元二次方程】——dotcpp编程 求方程 的根,用三个函数分别求当b^2-4ac大于0、等于0、和小于0时的根,并输出结果。从主函数输入a、b、c的值。 阅读详情

相关推荐

题目 1028: [编程入门]自定义函数求一元二次方程

题目描述:(时间限制: 1Sec 内存限制: 128MB) 求方程 的根,用三个函数分别求当b^2-4ac大于0、等于0、和小于0时的根,并输出结果。从主函数输入a、b、c的值。 输入: a b c 输出: x1=? x2=? 样例输入: 4 1 1 样例输出: x1=-0.125+0.484i x2=-0.125-0.484i 解决方法: 代码块: import java.util.Scanner; public class 一元二次方程 { public static void main(Strin

wnamej的博客 805

蓝桥 1028自定义函数求一元二次方程

题目 1028: [编程入门]自定义函数求一元二次方程 时间限制: 1Sec 内存限制: 128MB 提交: 9069 解决: 4883 题目描述 求方程 的根,用三个函数分别求当b^2-4ac大于0、等于0、和小于0时的根,并输出结果。从主函数输入a、b、c的值。 输入 a b c 输出 x1=? x2=? 样例输入 4 1 1 样例输出 x1=-0.125+0.484i x2=-0.125-0...

weixin_45733897的博客 450

Transformers 中的 Softmax 可以并行加速么?

通过融合前两个计算步骤,降低执行Reduce_max和Reduce_sum等操作的通信开销。利用共享内存来存储临时数据,以减少对全局内存的访问成本。

stephen147的博客 1235

自定义函数求一元二次方程(C语言版)

注意点: 输出的格式,多少位后小数。 scanf后要记得加& <0的情况要记得分类 题目描述 求方程 的根,用三个函数分别求当b^2-4ac大于0、等于0、和小于0时的根,并输出结果。从主函数输入a、b、c的值。 输入 a b c 输出 x1=? x2=? 样例输入 4 1 1 样例输出 x1=-0.125+0.484i x2=-0.125-0.484i 都很简单: #includ...

爱党人士 6513

道闸不自动落杆故障排查:从传感器原理到控制器调试全解析

在工业自动化和物联网系统中,传感器与控制器构成的闭环控制是保障设备可靠运行的核心。其基本原理是通过传感器采集环境状态,控制器依据预设逻辑做出决策并驱动执行器动作。这一技术价值在于实现了无人值守下的安全、高效自动化,广泛应用于智能交通、安防和智能楼宇等领域。以停车场道闸系统为例,其自动落杆功能高度依赖地感线圈与防砸雷达的协同。地感线圈作为触发单元,负责感知车辆接近;而防砸雷达则作为持续监测的安全单元,通过微波探测防砸区域内是否有障碍物,其信号是控制器执行落杆决策的关键依据。当系统出现车辆通过后闸杆不落的典型故

weixin_29190651的博客 313

QGroundControl或者华科尔地面站安装完打不开问题解决

QGroundControl 华科尔 打不开

wv112406的博客 4923

自定义函数求一元二次方程C语言版

解题思路: 一元二次方程 只含有一个未知数(一元),并且未知数项的最高次数是2(二次)的整式方程叫做一元二次方程。 一般式:ax²+bx+c=0(a≠0)。 其中ax²叫作二次项,a是二次项系数;bx叫作一次项,b是一次项系数;c叫作常数项 ```c 求根公式: ``` 利用一元二次方程根的判别式可以判断方程的根的情况 ▲ = b² - 4ac 一元二次方程的根与根的判别式 有如下关系: ① 当 ▲ > 0 时,方程有两个不相等的实数根; ② 当 ▲ = 0 时,方程有两个相等的实数根; ③ 当 ▲

m0_63568001的博客 1075

攻防世界-Reverse-Game

攻防世界,game,逆向

wuh2333的博客 777

自定义函数求一元二次方程-题解

自定义函数求一元二次方程-题解

m0_74920497的博客 508

iOS中.obj、.usdz、.dae和.scn格式之间的转化(思路清晰版)

作者最近在写项目的过程中遇到了一些3d模型格式问题,故写下这篇文章记录一下解决问题的过程。

yueliangmua的博客 5586

汽车ECU诊断入门:手把手教你用UDS协议(ISO14229)读取和清除故障码

本文详细介绍了如何使用UDS协议(ISO14229)进行汽车ECU诊断,包括故障码读取与清除的完整流程。从诊断环境搭建、UDS协议基础到实战案例分析,手把手教你掌握0x19诊断服务、安全访问机制等核心技能,适用于汽车电子工程师和诊断开发人员。

weixin_33701251的博客 457

[编程入门]自定义函数求一元二次方程

求方程 的根,用三个函数分别求当b^2-4ac大于0、等于0、和小于0时的根,并输出结果。从主函数输入a、b、c的值。

nuonuonuo7的博客 982

1、vectorCast单元测试常用操作

进入软件主页面,点击file,选择set working directory,随便选择一个保存该项目的目录即可。

weixin_59334478的博客 2158

C语言:1028.自定义函数求一元二次方程

C语言:1028.自定义函数求一元二次方程 题目描述: 求方程 的根,用三个函数分别求当b^2-4ac大于0、等于0、和小于0时的根,并输出结果。从主函数输入a、b、c的值。 题解: #include<stdio.h> #include<stdlib.h> #include<math.h> int main(int argc,char *argv[]) { float gen1(float a,float b,float c); float gen2(fl

weixin_41993485的博客 689

YOLOv8与Swin Transformer的完美结合:如何提升目标检测的精度与速度

Swin Transformer(Shifted Window Transformer)是一种新型的视觉Transformer架构,采用了局部窗口(Window)和局部窗口偏移(Shifted Window)的策略,极大减少了计算复杂度,同时保持了全局感知能力。局部窗口注意力:每个窗口内的元素进行自注意力计算,减少计算量。窗口偏移:通过在不同层次引入窗口偏移,增强了全局信息的交互。层级设计:通过堆叠多个层次的模块,逐渐捕捉不同尺度的特征。

shrgegrb的博客 2151

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

题目 1028: 自定义函数求一元二次方程

题目描述 求方程 的根,用三个函数分别求当b^2-4ac大于0、等于0、和小于0时的根,并输出结果。从主函数输入a、b、c的值。 输入 a b c 输出 x1=? x2=? 样例输入 4 1 1 样例输出 x1=-0.125+0.484i x2=-0.125-0.484i #include <stdio.h> #include <math.h>//为了引用sqrt()函数(开平方) void f1(double a,double b,double c);

这里有一堆废料,估计长期不再看了 590

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

php语言求二次方程根,C++通过自定义函数求一元二次方程的根

本文实例讲述了C++通过自定义函数求一元二次方程的根。分享给大家供大家参考,具体如下:/** 作 者: 刘同宾* 完成日期:2012 年 11 月 24 日* 版 本 号:v1.0* 输入描述:* 问题描述: 求一元二次方程的根。定义函数* 程序输出:* 问题分析:略* 算法设计:略*/#include#includeusing namespace std;double x,x1,x2,t; //...

weixin_39632891的博客 216

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

1028 自定义函数求一元二次方程

题目描述 求方程 的根,用三个函数分别求当b^2-4ac大于0、等于0、和小于0时的根,并输出结果。从主函数输入a、b、c的值。 输入 a b c 输出 x1=? x2=? 样例输入复制 4 1 1 样例输出复制 x1=-0.125+0.484i x2=-0.125-0.484i #include <stdio.h> #include <math.h>//为了引用sqrt()函数(开平方) void f1(double a,double b,double c); void f.

m0_68224121的博客 215

ACM训练系统 1028 [编程入门] 自定义函数求一元二次方程 C

本题需要的函数包括: 输入输出函数 stdio.h 用于输入输出数据。 数学函数 math.h 用于开平方等数学操作 开方函数 sqrt() 首先复习一下一元二次方程的解法 有实根: 没有实根 如果b^2-4ac>0 方程有两个实根,对应的函数如下 void lianggegen(int a,int b,int c) { float d=(float)(-b+sqrt((b*b-4*a*c))/(2*a)); float e=(float)(...

weixin_60883041的博客 331

自定义函数求一元二次方程(算法学习的第十天,C+Java(在学ing))

2020.5.1 学习第十天了吧,我都快记不清日子了~~~ 放假的第一天 早起码代码~~ 自定义函数求一元二次方程 Java 代码: import java.util.Scanner; class Solving { int a, b, c; Solving(int a, int b, int c) { this.a = a; this.b = b; this.c = c; ...

Blackzeus的博客 331

python自定义函数求面积_9. Python | 自定义函数_求一元二次方程根(代码)

练习请定义一个函数quadratic(a, b, c),接收3个参数,返回一元二次方程:ax2 + bx + c = 0的两个解。提示:计算平方根可以调用math.sqrt()函数:# -*- coding:utf-8 -*-import mathdef quadratic(a,b,c):if not isinstance(a+b+c,(int,float)):raise TypeError('b...

weixin_39556702的博客 621
上一篇: 求最小的起始正整数
下一篇: 字符串转换成十进制整数
python_198
博客等级 码龄3年 359粉丝 112原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

python_198

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值