/*
运行结果与书上不符以,疑为书籍排版错误。
书上原题:m(i)=4(1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 +……+ 1/(2i-1) - 1/(2i+1))
若i = 10,展开应为:m(i)=4(1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13 - 1/15 + 1/17 - 1/19 + 1/21)
i m(i)
10 3.232315809405593
20 3.1891847822775956
30 3.17384233719075
40 3.165979272843214
50 3.1611986129870484
60 3.1579849951686647
70 3.1556764623074756
80 3.153937862272616
90 3.1525813328751218
100 3.1514934010709927
*/
import java.util.Scanner;
public class ComputeOrderedSeries {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a digit number: ");
int number = input.nextInt();
displaySumOrderedSeries(number);
}
public static void displaySumOrderedSeries(int n) {
System.out.println("i\tm(i)");
for (int i = 10; i <= n; i += 10)
displaySumBody(i, sumOrderedSeries(i));
}
public static double sumOrderedSeries(int n) {
double m3 = 0, m5 = 0;
for (int i = 3; i <= 2 * n - 1; i += 2) {
m3 += 1.0 / i;
i += 2;
m5 += 1.0 / i;
}
return (1.0 - m3 + m5) * 4.0;
}
public static void displaySumBody(int i, double mi) {
System.out.println(i + "\t" + mi);
}
}
相关推荐
保姆级教程:手把手教你用RKISP TURN为RV1106生成和配置IQfile(附AIQ版本匹配避坑指南)
本文提供RV1106 ISP调试的完整指南,详细讲解如何使用RKISP TURN工具生成和配置IQfile,包括环境搭建、参数调试、设备树配置及常见问题解决方案。特别强调AIQ版本匹配的重要性,帮助开发者避免常见陷阱,提升图像信号处理效率。
css文字内容超出显示"...",可以控制行数
p.title{ overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 1;//设置行数,1超出一行...,2超出两行... -webkit-box-orient: vertical; }
TM1621/HT1621 段码LCD驱动器
TM1621 LCD 驱动器
java圆周率_Java简单计算圆周率完整示例
本文实例讲述了Java简单计算圆周率。分享给大家供大家参考,具体如下:这两天在网上看到一个题,已知Pi可以用函数4 * (1 – 1/3 + 1/5 – 1/7 + …) 计算,计算出小数点后五位(计算圆周率)。于是手动写了一个小demo,欢迎大家留言,进行交流与指教。完整示例代码如下:package math;public class PiTest {private static int byt...
【MCU】一种基于RTOS的无应答重发机制
文章目录一、背景描述二、结构框图三、基于RTOS的信号量的实现(3-1)思路描述(3-2)步骤(3-2-1)定义超时重发信号量(3-2-2)定义发送线程入口(3-2-3)定义接收线程入口四、基于定时器的实现(4-1)思路描述(4-2)步骤(4-2-1)创建定时器(4-2-2)定义定时器超时处理函数(4-2-3)定义发送线程入口(4-2-4)定义接收线程入口 一、背景描述 在微控制器之间进行数据通信时,大多需要添加无应答重发机制,以增强数据交互和通信的稳定性。 在使用UART通信的双方设备,当一次数据传输
百条网络工程师基础面试题(不断更新)
1)什么是链接? 链接是指两个设备之间的连接。它包括用于一个设备能够与另一个设备通信的电缆类型和协议。 2)OSI 参考模型的层次是什么? 有 7 个 OSI 层:物理层,数据链路层,网络层,传输层,会话层,表示层和应用层。 3)什么是骨干网? 骨干网络是集中的基础设施,旨在将不同的路由和数据分发到各种网络。它还处理带宽管理和各种通道。 4)什么是 LAN? LAN 是局域网的缩写。它是指计算机与位于小物理位置的其他网络设备之间的连接。 5)什么是节点? 节点是指连接发生的点。它可以是作为网络一部分的计算机
Introduction to Java Programming编程题5.13<数列求和>
/* Enter a digit number: 3 i m(i) 1 0.5 2 1.1666666666666665 3 1.9166666666666665 */ import java.util.Scanner;public class SumOrderedSeries { public static void main(String[] args) { Scan
KEGG数据库与KAAS工具:基因功能注释的实用指南
本文提供了使用KEGG数据库与KAAS工具进行基因功能注释的完整实用指南。详细阐述了如何从准备基因或蛋白序列开始,通过KAAS服务器获取KEGG Orthology(KO)编号,并解读注释结果。文章进一步介绍了如何利用KOBAS工具进行通路富集分析,将定性观察转化为定量洞察,并分享了提高注释准确率、处理大数据集及使用API等避坑技巧与高阶方法,为基因组学、转录组学研究者奠定坚实的数据分析基础。
MIT 6.006算法导论:从数据结构到动态规划的完整学习指南
算法与数据结构是计算机科学的核心基础,它们通过定义数据组织方式和问题求解步骤,构建了软件系统的效率基石。其原理在于利用时间与空间复杂度的权衡,通过渐进分析(如大O表示法)评估不同策略的性能。掌握这些基础概念的技术价值在于,它能培养开发者抽象问题、设计高效解决方案的系统性思维,而不仅仅是编写代码。这种能力在搜索引擎优化、数据库索引、网络路由等应用场景中至关重要,直接决定了系统的响应速度与资源利用率。本文聚焦于MIT 6.006这门经典课程,它体系化地讲解了从哈希表、二叉堆等基础数据结构到动态规划、图算法等高级
知识的定义与分类体系详解 - 从零基础到专业理解
知识的定义与分类体系详解 - 从零基础到专业理解
基于Python的智能动漫更新监控爬虫系统:从原理到实战
本文详细介绍了如何使用Python构建一个智能化的动漫更新监控系统,涵盖从基础爬虫到高级自动化监控的全套解决方案。文章将深入探讨最新的网络爬虫技术,包括异步请求、反反爬策略、智能解析算法等,并提供完整的代码实现和性能优化方案。通过本系统,用户可以实时获取多个动漫平台的更新信息,并通过多种渠道接收通知。关键词:Python爬虫、动漫监控、自动化通知、异步爬虫、反反爬策略。
递归函数总结
本文系统讲解了递归的概念、形态与优化方法。递归是函数调用自身的过程,具有两个核心特征:自我调用和终止条件。递归可分为线性递归(头递归/尾递归)和树形递归,不同形态在调用结构和执行流程上存在差异。文章通过时序图和调用树对比了头递归与尾递归的差异,解释了编译器为何只能优化尾递归。针对递归的性能问题,提出了三种优化方向:分而治之、动态规划/记忆化、DFS/BFS转换。重点分析了记忆化(缓存中间结果)和动态规划(自底向上求解)的原理,并以零钱兑换问题为例展示了动态规划的实现方法。文章指出朴素递归时间复杂度通常为指数
LinePhone3.2.7(android端最新版本) sip客户端
SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/
Introduction to Java Programming编程题9.1<检查SSN>
Enter your SSN: 123-45-666666 Invalid SSN. Enter your SSN: okl-33-4444 Invalid SSN. Enter your SSN: 123-45-6789 Valid SSN
jdk-8u144-linux-x64.tar.gz.
该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包
深度学习工具包 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');```[](https://bitdeli.com/free "Bitdeli Badge")
Introduction to Java Programming编程题7.4<计算每个雇员每周工作小时数>
/* result:----------------------------------------------- sony:java sony$ java EmployeeHours < EmployeeHours.txt Employee1: 41 Employee2: 37 Employee3: 34 Employee4: 32 Employee5: 31 Employee6: 28 Empl
OV9734 DATASHEET,完整规格书
OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等
Introduction to Java Programming编程题11.1<The triangle class>
运行结果:Triangle: side1 = 1.0 side2 = 1.0 side3 = 1.0 color: green filled: false Triangle: side1 = 1.0 side2 = 1.5 side3 = 1.0 color: yellow filled: trueGeometricObject.javapackage Uber; public class Geom
Introduction to Java Programming编程题9.31<刽子手游戏>
/* Enter a letter in word: ******** > t t is not in the word. Enter a letter in word: ******** > a Enter a letter in word: ******a* > l Enter a letter in word: ******al > n Enter a letter in word: ****
Introduction to Java Programming编程题8.13<返回二维数组中最大值及下标>
Enter the number of rows and columns of the array: 3 4 Enter the array: 11 33.5 88.1 4 0 -2.2 -10.1 -20 1.11 2.22 3.3 4.4 The location of the largest element is 88.1 at (0, 2)
Introduction to Java Programming编程题8.37<Guess the capitals>
运行结果:What is the capital of Alabama? Montogomery The correct answer should be Montgomery. What is the capital of Alaska? Juneau Your answer is correct. What is the capital of Arizona? PhoEnix The corre
Introduction to Java Programming编程题12.3<ArrayIndexOutBoundsException>
运行结果:Enter the array's index less than 100: -5 q 111 9 Out of bounds. Enter the array's index less than 100: qq Index must be digital. Enter the array's index less than 100: 5 Index 5: 144ArrayIndexOut
Introduction to Java Programming编程题12.1<NumberFormatException>
运行结果:br:javacode br$ javac NumberFormatException.java br:javacode br$ java NumberFormatException 45 34 Please use java NumberFormatException operand1 operator operand2 java NumberFormatException 45x +
Introduction to Java Programming编程题5.17<01矩阵>
public class MatrixZeroOne { public static void main(String[] args) { int randomNumber; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { randomNumber = (int)(Math.ran
求一个整数的所有位相加之和
/* Enter a digit number: 234 digit sum: 9 brown:javacode brown$ java SumDigits Enter a digit number: 1551 digit sum: 12 */import java.util.Scanner;public class SumDigits { public static void main(Str
introduction to Java Programming 编程题5.4<反向显示一个整数>
反向显示一个整数
Introduction to Java Programming编程题3.28<判断两个长方形是否相交>
/* Enter r1's center x-, y-coordinates, width, and height:2.5 4 2.5 43 Enter r2's cneter x-, y-coordinates, width, and height:1.5 5 0.5 3 r2 is inside r1Enter r1's center x-, y-coordinates, width, and
Introduction to Java Programming编程题5.6<打印数字三角形>
1 2 1 3 2 1 4 3 2 1 5 4 3 2 1 6 5 4 3 2 1 7 6 5 4 3 2 1 8 7 6 5 4 3 2 1 9 8 7 6 5 4 3 2 1
Introduction to Java Programming编程题12.2<InputMismatchException>
运行结果:Enter two digital number: tr ru hd Invalid digital number. Enter two digital number: 45 qa Invalid digital number. Enter two digital number: 12 11 12 + 11 = 23InputException.javaimport java.util.I
508




被折叠的 条评论
为什么被折叠?



