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…
POJ site spider
Description Design a crawler for problems of poj.org, crawl 100 problem details, and save as *.json file. Preparation The lab can be divided into these sections: Send a request and receive a responseParse the response and save the desired dataRepeatedly doing 1 and 2. Observation on url pattern The URLs of problems on poj all follow this format: http://poj.org/problem?id=<id> where <id> is an integer starting at 1000. So when we only need to send a request to this pattern, when <id> ranges from 1000 to 1099. Strategies against anti-crawler As a friendly crawler, we should not put much pressure on poj's server. This is something we should think about before we start coding. To avoid being banned, here are some simple strategies: Use fake UserAgents.Sleep for some seconds between 2 requests.If still get banned, we have to implement an ip-pool. Coding Parse response and save the data we want We can manually obtain the HTML code of websites using Firefox's view-source function. So we will start with the parsing. In this section, we will import…
Configure Vim on Linux Mint 20.03
This is just a simple record. About the configuring process on Windows, here is another blog. Version Info Vi IMproved 8.1 (2018 May 18) Huge version with GTK3 GUI. .vimrc[ref]无插件Vim配置文件vimrc推荐与各VIM配置项解释[/ref] " All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by " the call to :runtime you can find below. If you wish to change any of those " settings, you should do it in this file (/etc/vim/vimrc), since debian.vim " will be overwritten everytime an upgrade of the vim packages is performed. " It is recommended to make changes after sourcing debian.vim since it alters " the value of the 'compatible' option. runtime! debian.vim " Vim will load $VIMRUNTIME/defaults.vim if the user does not have a vimrc. " This happens after /etc/vim/vimrc(.local) are loaded, so it will override " any settings in these files. " If you don't want that to happen, uncomment the below line to prevent " defaults.vim from being loaded. let g:skip_defaults_vim = 1 " Uncomment the next line to make Vim more Vi-compatible " NOTE: debian.vim sets 'nocompatible'. Setting 'compatible'…
Crawl song lyrics in NetEase
Introduction Beginning to learn Python, @Zei_Wai and I want to do some simple tasks, instead of diving into the sea of the documentation of Python. Then we chose this: generating a WordCloud picture of the lyrics of NeteaseMusic Songlist. Using urllib package First we found an api of Netease: https://music.163.com/api/song/lyric?id=<song.id>&lv=1&kv=1&tv=-1 where <song.id> is the id of songs in Netease database. When we use web client to play music, the URL of music playing page contains this id. For a simple example, if we want to get the lyrics of Bad Apple!! we just need to do like this: Then we just need to get the songs' id in a automatic way, then we can generate a text file. But when we use this method to send request to Netease Songlist page, what it returns doesn't contain songid. This is the code we use:[ref]【python爬虫自学笔记】-----爬取网易云歌单中歌曲歌词[/ref] import json import requests import re import urllib from bs4 import * def get_html(url): myheaders = { "User-Agent": "Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11 ", "Referer": "http://music.163.com/", "Host": "music.163.com" } try:…
Dual-boot Win10 and Linux Mint
Introduction I already have Windows 10 installed on my computer, and want to install Linux to dual boot. Preparation I don't have any experience on installing a new OS. So I have to investigate enough to minimize the probability that emergencies happen. Distro I choose Linux Mint 20.03(Edge). This stable edition is distributed on Jan. 17, 2022. Some videos that helps to choose a distro (provided by @Erik): Linux HATES Me – Daily Driver CHALLENGE Pt.1 - YouTube Linus BREAKS Linux! - Daily Driver Challenge Reaction - YouTube Creating a bootable USB Stick[ref]Create the bootable media[/ref] Download the iso image from mirrors. I chose the one the SJTUG site provided. Download the iso file. Remember to check the file integrity using SHA256.[ref]Verify your ISO image[/ref] As I am now operating on Windows, call cmd and type command:[ref]How to verify the ISO image on Windows[/ref] CertUtil -hashfile <filename.iso> SHA256 where the <filename.iso> is the file name of the iso file. screenshot of my SHA256 check Download Etcher, install and run it. 16GB UDisk, after flashing Fundamental…
What do these Mojibake mean? – UTF-8 Encoding Scheme Exploration
This article may contain horrific and gory videos. Be careful when clicking on the URLs. If you have any discomfort when browsing, please stop and leave. / 本文可能含有恐怖、血腥性质的图片、视频。请谨慎进入文中的链接。如果您在浏览过程中产生任何不适,请停止浏览并离开。 Introduction We often meet mojibake, in games, web pages, or somewhere else. UTF-8 is the most widespread encoding scheme. These days my friends @叉叉 and @北嘲 find some weird videos on YouTube, with obscure titles and terrifying cover. We are curious about the origin of these creepy videos. This article is to record our exploration process.  Some Example Videos (Click with Caution, Collapsed by default).... ø·ø ̈ùšù„ø© ... ø£øoù†ùšø© ù„ù„ø£ø·ù ø§ù„ ... ù„ùšø ̈ùšø§.. آمراة تدعى أنها السيدة مريم العذراء بأنها متزوجة من المسيح Exploration Association with encoding When @叉叉 first send me the video title (.... ø·ø ̈ùšù„ø© ... ø£øoù†ùšø© ù„ù„ø£ø·ù ø§ù„ ... ù„ùšø ̈ùšø§), it reminds me of what my misconfigured C-language IDE returns me as console error info: What the IDE returns: "²»ÊÇÄڲ¿»òÍⲿÃüÁҲ²»ÊǿÉÔËÐеijÌÐò|| »òÅú´¦ÀíÎļþ¡£" This is apparently a decoding error. Characters are all Latin Characters. Remind me of some schemes like ISO 8859-1. @叉叉…
Expression Tree – BiTree’s application
Introduction An expression can be converted to a tree, when every operator in the expression is binocular. One who is familiar with Mathematica may also know Mathematica expressions are all pre-order expressions. PreOrder expressions in mma This cpp program is used to read a expression and convert to a tree in memory, and calculate its value by means of the tree. Code #ifndef LINK_QUEUE_H #define LINK_QUEUE_H /* * ===================================================================================== * * Filename: Link-Queue.h * * Description: Implement a link queue in C. * * Version: 1.0 * Created: 2021/10/20 23:22:12 * Compiler: gcc * Author: CuSO4_Deposit (Depoze), CuSO4D@protonmail.com */ #include <stdio.h> #include <iostream> #include <stdlib.h> #define TRUE 1 #define FALSE 0 #define SUCCESS 1 #define FAILURE 0 typedef int Status; typedef union{ float Number; char Operator; }OpElem; typedef struct{ bool tag; OpElem Elem; }QElemtype; typedef struct QNode{ QElemtype data; struct QNode* next; }QNode; typedef struct{ QNode* front; QNode* rear; }LinkQueue; // Function Declaration Status InitQueue(LinkQueue& Q); Status DestroyQueue(LinkQueue& Q); Status ClearQueue(LinkQueue& Q); bool QueueEmpty(LinkQueue Q); int QueueLength(LinkQueue Q); Status GetHead(LinkQueue Q, QElemtype& e); Status EnQueue(LinkQueue&…
PostOrderThreadTree – Implement in C
/* * ===================================================================================== * * Filename: ThrTree.cpp * * Description: A BiThrTree * * Version: 1.0 * Created: 2021/11/3 22:50:46 * Revision: none * Compiler: gcc * * Author: CuSO4_Deposit (Depoze), CuSO4D@protonmail.com */ #include <stdio.h> #include <iostream> #include <stdlib.h> #include ".\BiTreeForThr.h" #define TRUE 1 #define FALSE 0 #define SUCCESS 1 #define FAILURE 0 typedef int Status; typedef char TElemtype; typedef enum PointerTag{Child = 0, Thread = 1} PointerTag; typedef struct BiThrNode{ struct BiThrNode* lptr; PointerTag ltag; TElemtype data; struct BiThrNode* parent; PointerTag rtag; struct BiThrNode* rptr; }BiThrNode; BiThrNode* PostCopyTree(BiTNode* T){ /* * === FUNCTION ====================================================================== * Name: PostCopyTree * Description: Copy a Bitree T to a ThrTree in post order return the BiThrtree's root. * ===================================================================================== */ if(!T) return NULL; BiThrNode* newlp = PostCopyTree(T->lchild); BiThrNode* newrp = PostCopyTree(T->rchild); BiThrNode* newnode = (BiThrNode*)malloc(sizeof(BiThrNode)); newnode->data = T->data; newnode->lptr = newlp; newnode->rptr = newrp; newnode->ltag = Child; newnode->rtag = Child; newnode->parent = NULL; newlp->parent = newnode; newrp->parent = newnode; return newnode; } Status PostThreading(BiThrNode* ThrT, BiThrNode*& Pre){ /* * === FUNCTION ====================================================================== * Name: PostThreading * Description: Initialize…