VIM

[译]Vim每日技巧-平移

经常需要将文本左移或右移,Vim很容易实现。我喜欢在vimrc文件中设置shiftwidth=1,这样可以更好的控制平移。首先你要在vimrc中定义如下的片段:
vnoremap <
vnoremap > >gv
现在,使用块选择高亮选中一列文本(在Unix平台下用ctrl+v,在Windows下使用ctrl+q),再按>或<进行移动。
>>>> (将向右移动4个shiftwidth单位)
你也可以使用ex命令来实现。跳转到块的第一列输入ma(在normal模式下)来设置一个标签a。转到要平移的块的最后一行的第一列输入mb来设置一个标签b。
现在可以用下面的命令:
:’a,’b>>
将块向右移动两次。

本篇来源:Daily Vim: Text Editor Tips, Tricks, Tutorials, and HOWTOs: Shifting

VIM

[译]Vim每日技巧-Search Motions

你可以将搜索作为动作跟在一个操作后面。假设有下面的句子:
A quick brown fox jumps over the lazy dog.
Vim(Vi也行)允许你这样操作(译注:假设光标在句首):
y/over (将”A quick brown fox jumps “复制到默认的寄存器)
c/over (进入插入模式,并且只保留后半句”over the lazy dog”)
d/lazy (删除前大半句,只留下”lazy dog”)
等等

本篇来源:Daily Vim: Text Editor Tips, Tricks, Tutorials, and HOWTOs: Search Motions

SAGE作图实例:Runge现象

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
f(x)=1/(1+25*x^2)
R=PolynomialRing(QQ, 'x')
x4=[-1+2*i/4 for i in range(5)]
pts4=[(i,f(i)) for i in x4]
l4=R.lagrange_polynomial(pts4)
fig=plot(f(x))+plot(l4, color='black', linestyle='--')
x5=[-1+2*i/5 for i in range(6)]
pts5=[(i, f(i)) for i in x5]
l5=R.lagrange_polynomial(pts5)
fig=fig+plot(l5, color='green', linestyle=':')
x10=[-1+2*i/10 for i in range(11)]
pts10=[(i, f(i)) for i in x10]
l10=R.lagrange_polynomial(pts10)
fig=fig+plot(l10, color='red', linestyle='-.')
fig=fig+text('$O$',(-0.1,-0.1),color='black')
fig=fig+line([(1.21,0),(1.21,0)],marker='&gt;',markersize=7,color='black')+line([(0,1.97),(0,1.97)],marker='^',markersize=7,color='black')
fig.show(dpi=150,axes_labels=['$x$', '$y$'],axes_pad=0.01)

Sage总体来说非常不错,但还有不少小毛病:
1、命令的命名有问题。名为lagrange_polynomial,但返回的是已经展开的标准形式。插值多项式是唯一的,不如直接叫interpolation_polynomial。
2、没有显示坐标轴箭头的命令。
3、坐标轴标注的位置不符合习惯。

TikZ一例–简单流程图


下面那个大括号找了半天。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
\usetikzlibrary{arrows}
\usetikzlibrary{decorations.pathreplacing
}

% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=blue!20,
text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt
]
\tikzstyle{block} = [rectangle, draw, fill=blue!20,
text width=2em, text centered, rounded corners, minimum height=4em
]
\tikzstyle{line
} = [draw, -latex']
%\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
%    minimum height=2em]

\begin{tikzpicture}[scale=0.7, node distance = 2.0cm, auto]
\node [block] (problem) {\\\\\\};

\node [block, right of=problem] (model) {\\\\\\};
\path [line] (problem) -- (model);

\node [block, right of=model] (method) {数值计算方法};
\path [line] (model) -- (method);

\node [block, right of=method] (prog) {\\\\\\};
\path [line] (method) -- (prog);

\node [block, right of=prog] (comp) {\\\\\\};
\path [line] (prog) -- (comp);

\draw[decorate, decoration={brace, mirror}, very thick, blue] (0,-2) -- (3,-2);
\draw (1.5,-2.8) node {应用数学};

\draw[decorate, decoration={brace, mirror}, very thick, blue] (5.5,-2) -- (11.5,-2);
\draw (8.5,-2.8) node {计算数学};
\end{tikzpicture
}
VIM

[译]Vim每日技巧-快速全选

想快速全选?在normal模式下,试一下ggVG吧。

本篇来源:Daily Vim: Text Editor Tips, Tricks, Tutorials, and HOWTOs: Fast Select All

[转]SAGE tip: Fourier Series Approximation with Interactive mode

sws文件下载:Interactive mode of Fourier Series Approx

via Doxdrum’s Blog by doxdrum on 2/1/11


After my last post, about Fouries Series, I decided to give a try to the interactive mode of SAGE.

:-)

What did I do?

First I check out the examples worked at the Wiki page. In the section of graphics I got inspired from the post Interactive 2D Plotting by Timothy Clemans and Newton’s Method by William Stein post in the Calculus section. So… there it is!

The code is too long to be posted here… but here it goes anyway

1
var('x,n,i')
1
2
def error_msg(msg):
.. print '&lt;p style="font-family: Arial, sans-serif; color: #000;"&gt;&lt;span     style="color: red; font-weight: bold;"&gt;Error&lt;/span&gt;: %s&lt;/p&gt;' % msg
1
...
1
2
3
4
5
def a(f, n, init, final):
.. x = f.variables()[0]
.. L = (final - init)/2
.. coeff = integral(f(x)*cos(n*pi*x/L), (x,init,final))/L
.. return coeff

def b(f, n, init, final):
.. x = f.variables()[0]
.. L = (final – init)/2
.. coeff = integral(f(x)*sin(n*pi*x/L), (x,init,final))/L
.. return coeff

def FS(f, n, init, final):
.. x = f.variables()[0]
.. L = (final – init)/2
.. return a(f, 0, init, final)/2 + sum(a(f, i, init, final)*cos(i*x*pi/L)+b(f, i, init, final)*sin(i*x*pi/L), i, 1, n)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
@interact
def interactive_2d_plotter(clr=Color('green'), expression=input_box('x^2', 'Expression', str), x_range=range_slider(-6,6,1,(-4,4), label='X Range'), order=slider([0..100],None,None,3), square=checkbox(True, 'Square'), axes=checkbox(False, 'Show Axes')):
.. if expression:
..   try:
..      expression = SR(expression) # turn string into a Sage expression
..   except TypeError:
..      print error_msg('This is not an expression.')
..      return
..   try:
..      xmin, xmax = x_range
..      n = order
..      if square or not axes:
..         print "var('%s')nplot(%s).show(%s%s%s)" % (expression.variables()[0], repr(expression), 'aspect_ratio=1' if square else '', ', ' if square and not axes else '', 'axes=False' if not axes else '')
..         if square:
..            P = plot(FS(expression, n, xmin, xmax), xmin, xmax, color=clr) + plot(expression, xmin, xmax)
..            P.show(aspect_ratio=1, axes=axes)
..         else:
..            P = plot(FS(expression, n, xmin, xmax), xmin, xmax, color=clr) + plot(expression, xmin, xmax)
..            P.show(axes=axes)
..      else:
..         print "var('%s')nplot(%s)" % (expression.variables()[0], repr(expression))
..         P = plot(FS(expression, n, xmin, xmax), xmin, xmax, color=clr) + plot(expression, xmin, xmax)
..         P.show(axes=axes)
..   except ValueError:
..      print error_msg('This expression has more than one variable.')
..      return
..   except TypeError:
..      print error_msg("This expression contains an unknown function.")
..      return

because it’s almost in-understandable :-P

Some pictures!!!

The code is set to give the Fourier approximation of the f(x)=x^2 with aspect_ratio = (1,1).

Initial Plot. Approx. of x^2Initial Plot. Approx. of x^2

One can set a non one-to-one aspect_ratio, by un-checking the box,

Initial Plot with-no-squareInitial Plot with-no-square

And we can view the frame as well by checking the other box,

Initial plot no-square and frameInitial plot no-square and frame

The first box allows us to change the colour, by using a palette,

Initial plot with color-paletteInitial plot with color-palette

for example, set the colour to red,

Initial plot in redInitial plot in red

We can also change the function, to an exponential, f(x)=e^x,

Fourier approximation of the exponentialFourier approximation of the exponential

and change the domain of the function,

Changing the intervalChanging the interval

or the order of the approximation,

Exponential changing the order of the approximationExponential changing the order of the approximation

I published my sage file on my page (at the end of the page in the attached files)… for the sake of clarity (and completeness).

Enjoy,

Dox

[转]SAGE tip: Graphs of Elementary Numerical Integrals

原文在墙外,转发一下。对应的sws文件下载:Graphs of Elementary Numerical Integrals

via Doxdrum’s Blog by doxdrum on 1/30/11


Looking on the notebook worksheets publish on sagenb I found a very interesting application of the interactive mode, Interactive.

Since one can not look the result of the published notebooks, I use its code to playing around a little bit, so here are the plots.

The default function to be integrated is sin(x^2)+2, the interval of integration is set [-1,3], the number of partitions of the interval is 4, and the method is the mid-point,

Integration by mid-point method. Partition = 4Integration by mid-point method. Partition = 4

We can see the visual integration, the analitic result, the numerical one, and the error. :-) Nice, Isn’t it?

Let’s change the number of partitions, say to 10,

Integration by mid-point method. Partition = 10Integration by mid-point method. Partition = 10

Much better! But now, let’s try the other methods… left-point,

Integration by left-point method. Partition = 10Integration by left-point method. Partition = 10

The right-point,

Integration by right-point method. Partition = 10Integration by right-point method. Partition = 10

The upper-point,

Integration by upper-point method. Partition = 10Integration by upper-point method. Partition = 10

The lower-point,

Integration by lower-point method. Partition = 10Integration by lower-point method. Partition = 10

The trapezoid method,

Integration by Trapezoid method. Partition = 10Integration by Trapezoid method. Partition = 10

which is one of the best.

But finally the Simpson method,

Integration by Simpson method. Partition = 10Integration by Simpson method. Partition = 10

Impressive!!!

So, I think it’s a good idea to give a try to the interactive mode in SAGE, and if you go thru the code you’ll find out it’s not as difficult as it seems.

Enjoy!

Dox

VIM

[译]Vim每日技巧-文字对象

文字对象(text objects)是一些可以与操作符组合使用或用于visual模式的命令。基本上,你给出一个命令带上描述,Vim将其应用于相关的文字对象。可用的命令如下:

aw – 一个单词
iw – 单词的内部
aW – 一个单词(包括开头和结尾的空白)
as – 一个句子
等等

实际上,这样可以很快的维护文本块。比如,normal模式下,光标停在一个单词的中间。你输入caw,Vim就执行“改变一个单词”(change a word)的操作,即删除当前单词,并切换到插入模式,等待输入。关于文字对象的详细信息,请查看帮助,:help text-objects

本篇来源:Daily Vim: Text Editor Tips, Tricks, Tutorials, and HOWTOs: Text Objects

VIM

[译]Vim每日技巧-过滤

有时,使用外部命令来处理当前编辑的文件是很有用的。Vim很容易做到这一点,输入:%!command即可。比如,使用Unix的sort命令对当前文件进行排序:%!sort -u

本篇来源:Daily Vim: Text Editor Tips, Tricks, Tutorials, and HOWTOs: Filtering

注:Vim本身已有sort命令,:sort -u的效果和上面的命令完全一样。
另外一个例子是使用外部grep命令,只保留当前文件中包含指定字符串(如,yourword)的行,:%!grep yourword。当然这一效果也可以使用Vim自己的命令实现,:v/yourword/d

VIM

[译]Vim每日技巧-使用鼠标

我通常为了提高效率而避免使用鼠标。然而,有时候使用鼠标确实可以节省时间,比如调整窗口大小。当你用的不是Gvim时,Vim 7.x有一个选项来控制鼠标。要使用鼠标,输入:set mouse=a

本篇来源:Daily Vim: Text Editor Tips, Tricks, Tutorials, and HOWTOs: Mouse Support

无觅相关文章插件,快速提升流量