月度归档:2020年10月

Youth-Samuel Ullman

《springtime》皮埃尔·奥古斯特·库特

Youth is not a time of life, it is a state of mind, it is not a matter of rosy cheeks, red lips and supple knees, it is a matter of the will, a quality of the imagination, a vigor of the emotions, it is the freshness of the deep spring of life.
青春不是年华,而是心境;青春不是桃面、丹唇、柔膝,而是深沉的意志、恢宏的想象、炽热的感情;青春是生命的深泉在涌流。

Youth means a temperamental predominance of courage over timidity, of the appetite for adventure over the love of ease. This often exists in a man of 60 more than a boy of 20. Nobody grows old merely by a number of years; we grow old by deserting our ideals.
青春气贯长虹,勇锐盖过怯弱,进取压倒苟安。如此锐气,二十后生有之,六旬男子更多见。年岁有加,并非垂老;理想丢弃,方堕暮年。

Years may wrinkle the skin, but to give up enthusiasm wrinkles the soul. Worry, fear, self-distrust bows the heart and turns the spirit back to dust. Whether 60 or 16, there is in every human being’s heart the lure of wonders, the unfailing childlike appetite of what’s next and the joy of the game of living. In the center of your heart and my heart there is a wireless station: so long as it receives messages of beauty, hope, cheer, courage and power from the infinite, so long as you are young.
岁月悠悠,衰微只及肌肤;热忱抛却,颓唐必至灵魂。忧烦、惶恐、丧失自信,定使心灵扭曲,意气如灰。 无论年届花甲,抑或二八芳龄,心中皆有生命之欢乐,奇迹之诱惑,孩童般天真久盛不衰。人人心中皆有一个无线电台,只要你从天上人间接收美好、希望、欢乐、勇气和力量的信号,你就青春永驻,风华常存。

When the aerials are down, and your spirits are covered with snows of cynicism and the ice of pessimism. Then you’ve grown old even at 20, but as long as your aerials are up to catch waves of optimism, there’s hope you may die young at 80.
一旦天线降下,锐气便被冰雪覆盖,玩世不恭、自暴自弃油然而生,即便年方二十,实已垂垂老矣;然则只要竖起天线,捕捉乐观的信号,你就有望在八十高龄告别尘寰时仍觉年轻。
————王佐良译

matlab-用泰勒级数来计算定点x处的cos(x)值

function [cosValue,realcos,real_N] = mycos(x,N)
%mycos 通过N阶泰勒级数计算给定点x处的cos(x)。
% x 具体的x值
% N 泰勒级数的阶数 经验证(具体见下面mycosN函数)
% 将cosx x值转入0-2*pi内计算,取N=11 即可。
% cosValue 函数mycos的输出值
% real_N 满足精确度 10^(-4)下,真正需要的泰勒项数,用于检验,
%若出现 real_N>11,则本论述出错。算法错误
k=1:N;
a_k=double((-1).^k.*x.^(2*k)./factorial(2*k));
%泰勒级数每一项/factorial阶乘函数
cosValue=1+sum(a_k);%求和函数
realcos=cos(x);
while(abs(cosValue-realcos)>=0.001)
    N=N+1;
    a_k1=double((-1).^N.*x.^(2*N)./factorial(2*N));
    cosValue=cosValue+a_k1;
end
real_N=N;
end

验证“cosx x值转入0-2*pi内计算,取N=11 即可。

计算0-2*pi的cosx值,当精确度度要求为10的-4次方
考虑到cosx的周期性,计算时,x可以转换到0-2pi内计算,故改变 X的取样间隔。

泰勒级数展开的截断误差
(-1).^N.x.^(2N)./(2*N)的阶乘 考虑展开式中的每一项,
当N值越大,分母上的x的2n次方幂次讲远远大于分母上的阶乘项.
自然若是取N趋向于无穷,可解出cosx的准确值;但我们计算时候,必定涉及到截断(有限项)
问题:
1.是否是x取值越大,泰勒级数展开项要求越多?
2.到底N到多少停止,才会避免截断误差(可能最后几项使得整体计算偏移量巨大)?


检测有:
1.
X=0:0.0001:2pi; (real_max)Nmax=11
X=0:0.00001:2pi)(real_max)Nmax=11

2.当带入 mycos(x,N)(x=0:0.0001:2pi;N=11时)
计算上述两个x的离散点集合时候, 都成功计算出了满足精确度要求的cos值

3.plot(x,N)(x=0:0.0001:2pi,N=11)
画出图像,图像同cosx的图像(见后附图

所以,根据以上两点,这个问题,我们将之浓缩在0-2*PI区间内便不需考虑,取N=11时
% 认为满足cos值的计算

plot(x,cosValue,'-x','MarkerIndices',1:1:length(cosValue));
%每隔一点显示一个交叉标记,用实线连接
>> xlabel('x=0:0.001:2*pi');
>> ylabel('cosx 值');
>> print('-dpng','-r100','pic1')
% 输出png照片 -r 设置图像分辨率(dpi) 默认图片大小 8inx6in
function [cosValue,realcos,real_NmaxN,real_max] = mycosN(X,N)
%mycos 通过N阶泰勒级数计算给多个定点处的cos(x)。并计算实际满足精确度时,在给定输入定点下(可能这些定点取不到最多展开项),所需要展开的最多项数目
% X 多个定点的数组集合 
% N 泰勒级数的阶数
% cosValue: N项泰勒计算下,定点的cos值(数组)
% realcos:  matlab内置cos函数的cos值(数组)
% real_NmaxN:满足10的-4次方精确度下,对于各点所真实需要的泰勒展开项数
% real_max: real_NmaxN的最大值,即满足10的-4次方精确度下,泰勒展开的一般需要项数


real_Nmax=0;
cosValue=zeros(1,length(X));
realcos=zeros(1,length(X));
real_NmaxN=zeros(1,length(X));
i=0;
for j=X %j将遍历数组X
i=i+1;
k=1:N;
a_k=double((-1).^k.*j.^(2*k)./factorial(2*k));
cosValue(i)=1+sum(a_k);
realcos(i)=cos(j);
cos_compare=cosValue(i);
while(abs(cos_compare-realcos(i))>=0.0001)
    N=N+1;
    a_k1=double((-1).^N.*j.^(2*N)./factorial(2*N));
    cos_compare=cos_compare+a_k1;
end
real_N=N;
if(real_N>real_Nmax)
    real_Nmax=real_N;
end
real_NmaxN(i)=real_Nmax;
end
real_max=max(real_NmaxN);
end

从本质来讲,数学符号是一种通用语言,它能应用到包括matlab在内的任何编程语言。

Programming with MATLAB for Scientists, A Beginner’s Introduc