求助! matlab程式!

請問依下各位先進 以下程式要如何寫呢 小弟感激不盡

Develop an m-file named fun_xb that evaluates the flowing series:

f( x )=x-x^2/2+x^3/3-..+(-1)^(n+1)*x^n/n

The values of x and n are to given by input. Test the function by comparing the result with hand calculations for x=1 and n=4 .The foregoing sreies is a truncated Maclaurin expansion of log(1+x) and coverges for -1

Knowing this,test your function for selected x value, such as x=-0.5 and 0.5,with n= 1,2,3,5,10,20,50,and compare with log(1+x). (Convergence becomes increasingly difficult as x approaches -1 or 1)
2004-10-19 17:19 發佈
文章關鍵字 MATLAB 程式
@@居然有人問matlab~
這個其實不難吧~重點就是要寫一個while loop (while i 少於或= n)
i是每個term的"編號"
如i=1, term = x
i = 2, term = -x^2/2
i = 3, term = x^3/3
然後每次loop的時候就算一個term出來
f( x )就是全部terms的總數
loop後面就放 i=i+1

大概意思就是這樣~試一下吧:)
不要叫我把程式寫出來給你
Knowing this,test your function for selected x value, such as x=-0.5 and 0.5,with n= 1,2,3,5,10,20,50,and compare with log(1+x). (Convergence becomes increasingly difficult as x approaches -1 or 1)

題目的下半段 不知道位呵顯示不出來
應該是系統把『>』、『<』這兩個符號誤判為HTML語法了...
把這兩個符號用全形表示就OK啦~ (H)
完整的問題是這樣吧..

Develop an m-file named fun_xb that evaluates the flowing series:

f( x )=x-x^2/2+x^3/3-..+(-1)^(n+1)*x^n/n

The values of x and n are to given by input. Test the function by comparing the result with hand calculations for x=1 and n=4 .The foregoing series is a truncated Maclaurin expansion of log(1+x) and coverges for -1<X<1.

Knowing this,test your function for selected x value, such as x=-0.5 and 0.5,with n= 1,2,3,5,10,20,50,and compare with log(1+x). (Convergence becomes increasingly difficult as x approaches -1 or 1)


Test的部分應該不難吧?
手算部分就直接算
至於log(1+x)也不難compute啊
就隨便選個x值~n就用那些指定的
然後跟f( x )算出來的結果比較就可以了
可以plot graph來做具體的比較
life is an eternal flight of myself from myself.
x=-1:0.1:1;f=0;x1=0.1:0.1:1;
for n=1:550;
f=f+(-1).^(n+1).*(x.^n)./n
end
plot(x,f,x1,log(1+x1),'ro')
grid

寫出來了
內文搜尋
X
評分
評分
複製連結
Mobile01提醒您
您目前瀏覽的是行動版網頁
是否切換到電腦版網頁呢?