Category: Math&Sci

4 Posts

Neat examples of mathematica
This post will be updated from time to time as soon as any neat trick come out. Generate a an iterated logistic map I didn't come out this method, it's in the official documentation of mathematica. ListPlot[Table[Thread[{r, Nest[r # (1 - #) &, Range[0, 1, 0.01], 1000]}], {r, 0, 4, 0.01}]] output Count the number of Wednesdays on Dec 25th in 400 yrs Tally[DayName /@ Tuples[{Range[0, 399], Range[12, 12], {25}}]] Output: {{Monday, 56}, {Tuesday, 58}, {Wednesday, 57}, {Thursday, 57}, {Saturday, 56}, {Sunday, 58}, {Friday, 58}} Find the kth Chebyshev Polynomial Nest[{2 x #[[2]] - #[[1]], 2 x (2 x #[[2]] - #[[1]]) - #[[2]]} &, {1, x}, 3][[2]]// Expand Output: -7 x + 56 x^3 - 112 x^5 + 64 x^7 (The 7th Chebyshev Polynomial)
Numerical Analysis – Lab
Index Lab2 - Direct Methods for Solving Linear EquationsLab3 - Inverse Power Method to Solve EigenvalueLab4 - Jacobi Method to Solve EigenvalueLab 5 - Cubic Spline InterpolationLab 6 - FFT & IFFTLab 7 - Romberg Integral Lab2 - Direct Methods for Solving Linear Equations Description Use C/C++, implement the following algorithms: Gaussian EliminationDoolittle Decomposition Implement Predefinition and Useful functions #include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> #include <fstream> #include <math.h> using namespace std; #define SUCCESS 0 #define FAILURE 1 #define INPUTPATH "./InputData.txt" typedef int Status; typedef double* Vector; typedef double** Matrix; Status PrintMatrix(int n, Matrix A){ /* * === FUNCTION ====================================================================== * Name: PrintMatrix * Description: Print the Matrix A to the terminal. n is the Dimension of A. * ===================================================================================== */ for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ printf("%.2lf\t", A[i][j]); } printf("\n"); } return SUCCESS; } Status PrintVector(int n, Vector v){ /* * === FUNCTION ====================================================================== * Name: PrintVector * Description: Print the Vector v to the terminal(in row form). n is the Dimension…
Probability of Christmas on Wednesday
Original Problem Proof: In the system of the current Common Era, the probability of Christmas on Wed. is not 1/7. What exactly the probability is In 400 years there are 303 non-leap years and 97 leap years. Total number of days: $$T = 303\cdot 365 + 97\cdot 366\equiv 303 + 97\cdot 2\equiv 0\pmod 7.$$ This means: If the Christmas is on Mon. in year x, then it would be on Mon. in year (x + 400). That's to say, there's a difference between a day of the week and another day of the week. Solve in C /* * ===================================================================================== * * Filename: LeapYear_Xmas.cpp * * Description: A program to count which day of the week does the X-mas falls. * * Version: 1.0 * Created: 2021/10/9 20:31:35 * Revision: none * Compiler: gcc * * Author: CuSO4_Deposit, CuSO4D@protonmail.com * * ===================================================================================== */ #include <stdio.h> #include <iostream> #define TRUE 1 #define FALSE 0 #define Status int #define SUCCESS 1 #define FAILURE 0 #define FEB29 59 #define DEC25_nonleap 358 //Function Declaration bool ifLeap(int year); Status RunCalendar(int…
对数(logarithm)
引言 Introduction 给我空间、时间及对数,我就可以创造一个宇宙。伽利略 对数是一个有用的数学工具,它是指数的逆运算。在数学史上它的出现先于指数,纳皮尔在1614年出版的《奇妙的对数定律说明书》中正式地引入了对数。它的出现,让人们可以更轻松地考虑很大的数字,对天文学的发展起到了很大的作用。它的意义在于可以将指数取下来,将幂运算转化为乘法运算。 The logarithm is a useful mathematical tool which is the inverse of the exponent. It preceded exponents in the history of mathematics, and was formally introduced by Napier in 1614 in his A Description of the Wonderful Law of Logarithms.It has been instrumental in the development of astronomy by making it easier to consider very large numbers.Its significance lies in the ability to take down exponents and convert power operations into multiplication operations. 定义 Definition 虽然对数的出现先于指数,但我们依然可以依赖指数来定义对数,以便于理解。 若$a^x = y(a>0, a \neq 1)$,则有$$ x = \log_a y. $$也就是说,$\log_a y$定义为:$a$的多少次幂为$y$($a^? = y$).在$\log_a y$中,称$a$为底数,$y$为真数。 对数函数,是以x为自变量的函数$f$: $$f(x)=\log_a x.$$它的定义域是$(0,+\infty)$,且要求$a>0, a\neq 1.$ 值域为$\mathbb{R}.$ 它将任意一个在定义域内的输入$x$,映射为$a^? = x$中?的值,从而我们可以通过函数快速找到$a$的多少次幂等于一个变量。 $a>0, a\neq 1$ 和 $x\in (0,+\infty)$ 保证了函数的连续性。从指数函数的角度来考虑: 当$a<0$时,相当于问$$(-c)^? =x. $$以负数为底的指数函数还没有很好的定义,仅考虑x取整数时,函数值就会在正负值间反复跳动。 当$a = 0$或$a = 1$时,相当于问$$0^? = x, 1^? = x.$$我们知道这个问题是通常没有解的,因此不进行研究。 而对$x$的限制就来源于$a^? = x$中指数函数的输出一定大于0. 图像和性质 Graph&Properties 图像 Show[{Plot[Log[E, x], {x, 0, 4}]}, Plot[Log[1/E, x], {x, 0, 4}]] 对数函数的图像在$a$取在1两侧时有所不同,这是容易理解的。因为一个小于1的数的?次幂等于y,则随着y的减小?应当增大;而大于1的数的?次幂等于y,则随着y的减小?也应当减小。 对数函数是单调的。递增或递减取决于底数a的范围。 对数函数图像必过$(1,0)$点,这是因为$a^0 = 1\Leftrightarrow \log_a 1 = 0.$ 性质 对数函数有如下的运算性质: 定义: $$a^{\log_a x} = x.$$ 同底数的对数相加,底数不变,真数相乘: $$\log_c a+ \log_c b = \log_c ab.\Leftrightarrow c^x\cdot c^y = c^{xy}.$$ 以同一个数做底,若真数互为倒数,则对数互为相反数: $$\log_c a = -\log_c {\frac{1}{a}}.\Leftrightarrow c^x…