學習筆記:郭彥甫 (yan-fu kuo), 台大生機系 , matlab教學 - 10數值微積分
representing polynomials in matlab
values of polynomials:polyval()
a = [9,-5,3,7];
x=-2:0.01:5;
f = polyval(a,x);
plot(x,f,'linewidth',2);
xlabel('x');
ylabel('f(x)');
set(gca,'fontsize',14)
polynomial differentiation(多項式微分):polyder()
>> p = [5
0 -2
01];
>> polyder(p)
ans = 20
0 -4
0>> polyval(polyder(p),7)
ans = 6832
exercise
polynomial intergration(積分):polyint()
numerical differentiation (數值微分):diff()
calculating a secant line(割線) in the vicinty(附近) of x0x0
f′(x
0)=limh→
0f(x
0+h)
−f(x
0)h f′(
x0)=
limh→0
f(x0
+h)−
f(x0
)h
where
h h
represents a small change in
x' role="presentation" style="position: relative;">xx.
diff() : calculates the differences between adjacent(附近的) elements of a vector
>> x = [125
21];
>> diff(x)
ans = 1
3 -3 -1
exercise : obtain the slope(斜率) of a line between 2 points (1,5) and (2,7)
x = [1
2];y=[5
7]slope = diff(y)./diff(x)
given f(
x)=s
in(x
) f(x
)=si
n(x)
, find f′
(x0)f′
(x0)
at x0=
π/2 x0=
π/
2using h=
0.1 h
=0.1
f′(x0
)=limh→0
f(x0
+h)−
f(x0)hf
′(x0
)=
limh→0
f(x0
+h)−
f(x0
)h
>> x0 = pi/2
x0 = 1.5708
>> h=0.1
h = 0.1000
>> x = [x0 x0+h]
x = 1.5708
1.6708
>> y = [sin(x0) sin(x0+h)]
y = 1.0000
0.9950
>> m = diff(y)./diff(x)
m = -0.0500
exercise
how to find the f′
f
′over an interval(區間) [0
,2π]
[ 0,
2π]?
various step size
exercise
second and third derivatives(二階、三階導)
numerical integration(數值積分)
numerical quadrature rules(數值求積分準則)
midpoint rule using sum()
trapezoid rule using trapz()
second-order rule:1/3 simpson』s
>> h = 0.05;
>> x = 0:h:2;
>> y = 4*x.^3;
>> s = h/3*(y(1)+2*sum(y(3:2:end-2))+4*sum(y(2:2:end))+y(end))
s = 16
comparison
review of function handles(@)
numerical intergration:integral()
double and triple integrals(雙重和三重積分)
MATLAB數值法與微積分
函式之微分為求函式對自變數之導數,或為其斜率 利用數值方法則可以解出其他相關之問題,其應用部份已在前章討論。數值微分有兩種應用,其一是在資料收集完備後,分析其變化速度 其二為即時估計或量測速率。後者需要快速演演算法才能有立即反應。計算斜率,依其定義即為dy dx,在數值分析上必須轉化為可量測之變化量...
Matlab 數值微積分與方程求解
專題六 數值微積分與方程求解 目錄 一 數值微分與數值積分 1.數值微分 2.數值積分 二 線性方程組求解 先說差分。差分可以分為向前差分,向後差分和中心差分。三者分別如下表述 matlab提供了求向前差分的函式diff,其呼叫格式有3種 舉個例子 求向量 1,34,54,32,56,78 的一階向...
Matlab 多項式及數值微積分
differentiation微分 兩個多項式相乘時,兩個多項式用兩個矩陣接收,利用conv卷積函式進行合併 integration積分數值微分g colormap lines hold on for i 1 4 x 0 power 10,i pi y sin x m diff y diff x p...