Matlab
qshbbh
这个作者很懒,什么都没留下…
展开
-
欧拉习题40
题目如下:An irrational decimal fraction is created by concatenating the positive integers:0.123456789101112131415161718192021...It can be seen that the 12thdigit of the fractional part is 1.Ifdnrepresents thenthdigit of the fractional part, find ...原创 2021-11-13 16:55:14 · 626 阅读 · 0 评论 -
欧拉习题39
题目如下Ifpis the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions forp= 120.{20,48,52}, {24,45,51}, {30,40,50}For which value ofp≤ 1000, is the number of solutions maximised?代码clear;...原创 2021-11-13 16:53:21 · 686 阅读 · 0 评论 -
欧拉习题38
题目如下:Take the number 192 and multiply it by each of 1, 2, and 3:192 × 1 = 192192 × 2 = 384192 × 3 = 576By concatenating each product we get the 1 to 9 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1,2,3)The s原创 2021-11-13 16:51:27 · 848 阅读 · 0 评论 -
欧拉习题37
题目如下:The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37, and 3.原创 2021-11-13 16:48:30 · 784 阅读 · 0 评论 -
欧拉习题36
题目如下:The decimal number, 585 = 10010010012(binary), is palindromic in both bases.Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.(Please note that the palindromic number, in either base, may not inclu.原创 2021-11-13 08:45:57 · 786 阅读 · 0 评论 -
欧拉习题35
题目如下:The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.How many circular primes are t原创 2021-11-13 00:46:06 · 698 阅读 · 0 评论 -
欧拉习题34
题目如下:145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.Find the sum of all numbers which are equal to the sum of the factorial of their digits.Note: As 1! = 1 and 2! = 2 are not sums they are not included.采用暴力方法clear;clc;close all原创 2021-11-13 00:17:10 · 637 阅读 · 0 评论 -
欧拉习题33
题目如下The fraction49/98is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that49/98=4/8, which is correct, is obtained by cancelling the 9s.We shall consider fractions like,30/50=3/5, to...原创 2021-11-12 23:11:01 · 1026 阅读 · 0 评论 -
欧拉习题32
题目如下:We shall say that ann-digit number is pandigital if it makes use of all the digits 1 tonexactly once; for example, the 5-digit number, 15234, is 1 through 5 pandigital.The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing m...原创 2021-11-12 22:38:23 · 629 阅读 · 0 评论 -
欧拉习题31
题目如下:In the United Kingdom the currency is made up of pound (£) and pence (p). There are eight coins in general circulation:1p, 2p, 5p, 10p, 20p, 50p, £1 (100p), and £2 (200p).It is possible to make £2 in the following way:1×£1 + 1×50p + 2×20p + 1原创 2021-11-12 12:07:05 · 1589 阅读 · 0 评论 -
欧拉习题30
题目如下:Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:As 1 = is not a sum it is not included.The sum of these numbers is 1634 + 8208 + 9474 = 19316.Find the sum of all the numbers that ..原创 2021-11-02 11:10:20 · 704 阅读 · 0 评论 -
欧拉习题29
题目如下:Consider all integer combinations ofabfor 2 ≤a≤ 5 and 2 ≤b≤ 5:=4, =8, =16, =32=9, =27, =81, =243=16, =64, =256, =1024=25, =125, =625, =3125If they are then placed in numerical order, with any repeats removed, we get the following sequence...原创 2021-11-02 11:05:32 · 613 阅读 · 0 评论 -
欧拉习题28
题目如下:Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:2122 23 242520 78 91019 6 12 1118 54 3121716 15 1413It can be verified that the sum of the numbers on the diag...原创 2021-11-02 10:50:30 · 603 阅读 · 0 评论 -
欧拉习题27
题目如下:Euler discovered the remarkable quadratic formula:It turns out that the formula will produce 40 primes for the consecutive integer values0≤n≤39. However, whenn=40,+40+41=40(40+1)+41is divisible by 41, and certainly whenn=41,+41+41is clearl...原创 2021-11-02 10:39:34 · 803 阅读 · 0 评论 -
欧拉习题26
题目如下:A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given:1/2 = 0.5 1/3 = 0.(3) 1/4 = 0.25 1/5 = 0.2 1/6 = 0.1(6) 1/7 = 0...原创 2021-11-01 15:38:20 · 714 阅读 · 0 评论 -
欧拉习题25
题目如下:The Fibonacci sequence is defined by the recurrence relation:Hence the first 12 terms will be:The 12th term, F12, is the first term to contain three digits.What is the index of the first term in the Fibonacci sequence to contain 1000 digi原创 2021-11-01 15:16:47 · 555 阅读 · 0 评论 -
欧拉习题24
题目如下:A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic pe原创 2021-11-01 15:02:07 · 727 阅读 · 0 评论 -
欧拉习题23
题目如下:A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.A numbernis called..原创 2021-11-01 14:52:49 · 1217 阅读 · 0 评论 -
欧拉习题22
题目如下:Usingnames.txt(right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its al..原创 2021-11-01 14:06:28 · 636 阅读 · 0 评论 -
欧拉习题17
题目如下:If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would原创 2021-11-01 12:29:45 · 775 阅读 · 0 评论 -
欧拉习题16
题目如下:and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.What is the sum of the digits of the number ?数值计算不行,采用符号计算sum(char(sym(2)^1000)-'0')原创 2021-11-01 01:15:39 · 175 阅读 · 0 评论 -
欧拉习题15
题目如下:Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.How many such routes are there through a 20×20 grid?这属于经典的排列组合题目,常在小学奥数上出现,一般有两种做法,动态规划和组原创 2021-11-01 01:08:49 · 265 阅读 · 0 评论 -
欧拉习题14
题目如下:The following iterative sequence is defined for the set of positive integers:n→n/2 (nis even)n→ 3n+ 1 (nis odd)Using the rule above and starting with 13, we generate the following sequence:13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1It...原创 2021-11-01 00:55:02 · 304 阅读 · 0 评论 -
欧拉习题13
题目如下:Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.371072875339021027987979982208375902465101357402504637693767749000971264812489697007805041701826053874324986199524741059474233309513058123726617309629919422原创 2021-11-01 00:24:39 · 239 阅读 · 0 评论 -
欧拉习题21
题目如下:Let d(n) be defined as the sum of proper divisors ofn(numbers less thannwhich divide evenly inton).If d(a) =band d(b) =a, wherea≠b, thenaandbare an amicable pair and each ofaandbare called amicable numbers.For example, the pro...原创 2021-10-31 00:54:53 · 276 阅读 · 0 评论 -
欧拉习题20
题目如下:n! meansn× (n− 1) × ... × 3 × 2 × 1For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.Find the sum of the digits in the number 100!MATLAB需要采用符号计算sum(char...原创 2021-10-31 00:41:47 · 203 阅读 · 0 评论 -
欧拉习题19
题目为:You are given the following information, but you may prefer to do some research for yourself.1 Jan 1900 was a Monday. Thirty days has September, April, June and November. All the rest have thirty-one, Saving February alone, Which has twenty-e原创 2021-10-31 00:22:55 · 207 阅读 · 0 评论 -
欧拉习题67
该题目和第18题类似,只是数据大一些By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23.3742468 593That is, 3 + 7 + 4 + 9 = 23.Find the maximum total from top to bottom int...原创 2021-10-28 23:34:22 · 260 阅读 · 0 评论 -
欧拉习题18
最近由于忙,很久不写了,今天和朋友谈到如何学习编程,然后打开了欧拉习题,正好这个题目没有做,想了一下,写了一个方法,记录下来,供爱好者参考题目:By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23.3742468 593That is, 3 + 7 + 4 +...原创 2021-10-28 15:13:14 · 246 阅读 · 0 评论 -
最大上升子串的MATLAB程序实现
cody上有个最长字串问题,比如,数组,x = [8, 24, 7, 35, 23, 52, 39, 64, 78], 最长的严格上升字串为[8, 24, 35, 52, 64, 78], 长度为6这个题目我个人的做法是,构造一个辅助的数组y, y的第i个元素表示,x的第1个元素到x的第i个元素之间,最大的上升字串的长度,关键就是下一步的思路那么y的第i+1个元素的,就是x的1到i的元素中那些小于x的第i+1个元素的辅助数组对应的y的值加1.假设i=4,我们可以看到y(1) = 1, 对应.原创 2021-04-20 12:07:45 · 179 阅读 · 0 评论 -
用MATLAB直接提取变量元素的方法
今天看到知乎上haitao的博客https://zhuanlan.zhihu.com/p/341374091, 想到关于MATLAB的这个索引方法会带来的一些好处,以及自己对链式语法的理解,写下这篇博客。1. 关于函数返回值的属性的直接访问在MATLAB里面,一般是不支持双括号的索引方式,比如我们需要提取魔方矩阵的第二行的元素>> magic(3)(2,:)Error: Indexing with parentheses '()' must appear as the last原创 2021-01-03 11:00:56 · 5434 阅读 · 0 评论 -
冒泡排序MATLAB实现
clear;clc;close allx = [4,3,1,6,7,5,2,1,5,6,7,8];n = length(x);for i = 2 : n-1 for j = n : -1 : i if x(j) < x(j-1) x([j,j-1]) = x([j-1,j]); end endend原创 2019-12-06 10:27:11 · 6124 阅读 · 2 评论 -
MATLAB实现堆排序
clear;clc;close allx = [4,3,1,6,7,5,2,1,5,6,7,8];node = floor(length(x)/2);for i = node : -1 : 1 x = heap(x, i, length(x));endfor i = length(x) : -1 : 1 x([1,i]) = x([i,1]); x = heap...原创 2019-12-06 10:07:08 · 1306 阅读 · 2 评论 -
Matlab 遗传算法求解TSP问题
function varargout = tsp_ga(xy,dmat,pop_size,num_iter,show_prog,show_res)%TSP_GA Traveling Salesman Problem (TSP) Genetic Algorithm (GA)% Finds a (near) optimal solution to the TSP by setting up a转载 2013-03-17 23:43:55 · 5667 阅读 · 0 评论 -
Matlab 枚举法求解八皇后问题
Matlab在矩阵处理方面有着天然的优势,而现在计算机的处理速度枚举8皇后问题已经不是问题clear;clc;close allcols=perms(1:8); % 皇后所在列的位置S=size(cols,1);M=zeros(8,8,S); % 存储所以情况的矩阵M(sub2ind(size(M), repmat((1:8)',1,S), cols', repmat(1:S原创 2013-03-17 20:31:49 · 3561 阅读 · 0 评论 -
Matlab 模拟四人追逐问题
clear;clc;close allrectangle('Position',[1,1,1,1],... 'Curvature',[0,0],... 'LineWidth',2,'LineStyle','-')axis([0.9 2.1 0.9 2.1])daspect([1,1,1])x=[1 1 2 2];y=[1 2 2 1];n=10000;axis off原创 2013-03-17 23:39:33 · 4873 阅读 · 0 评论 -
Matlab画的玫瑰花
这是大约3年前写的程序,现在贴处理,存在很多需要优化的地方,有空的话我在简化简化function plot_rosedraw_main(450,90);function draw_main(x,y)%粉红色玫瑰arcdata{1}=[65 -60 150 350 8 66 -54 300 470 8 65 -56 30 230 10 64 -57 300 4原创 2013-03-17 20:37:31 · 27118 阅读 · 2 评论 -
Matlab 0-1规划求解八皇后问题
这是我以前写的一个程序,发布在一些Matlab的论坛,现在搬过来吧clear;clc;close allN=8;c=ones(N);% 行求和blkele=num2cell(c,2);A1=blkdiag(blkele{:});% 列求和A2=repmat(eye(N),1,N);Aeq=[A1;A2];beq=ones(2*N,1);% 斜线情况判断M=N-2;A=z原创 2013-03-17 19:59:46 · 2634 阅读 · 0 评论 -
Matlab 求解数独的程序
数独是近年来非常流行的游戏,有很多解法,在mathworks的file exchange里面可以找到很多,但我觉得下面的这个递归解法是比较简洁的。来自Mathworks function S = sodoku(M,S)%[S,Mout] = sodoku(M,[S])%%A recursive program that solves 'sodoku' puzzles.%%In转载 2013-03-17 19:53:53 · 7305 阅读 · 3 评论 -
Matlab 广度优先搜索求解迷宫问题
function BFS_Maze(maze)% maze:是迷宫矩阵,其中0表示可以去走的路% 1表示障碍% 2表示入口% 3表示出径% 5表示路径% 0 2 0 0 1%原创 2013-03-15 20:17:41 · 3135 阅读 · 0 评论