2011-10-05 162 views
-8

我的代碼輸出給了我,如果,exact_answer,然後一個矢量輸出與N條目。我不確定如何取消該條目。例如,它看起來像下面這樣:抑制輸出MATLAB

exact_answer = 

    0.2642 


If = 

    0.1882 


ans = 

     0 0.1637 0.2681 0.3293 0.3595 0.3679 

我不想輸出答案。 -

function g = LaplaceTransform(s,N) 
     % define function parameters 
     a=0; 
     b=1; 
     h=(b-a)/N; 
     x = 0:h:1; 
     % define function 
     g = ff(x).*exp(-s*x); 

% compute the exact answer of the integral 
exact_answer=antiderivative(b,s)-antiderivative(a,s) 
% compute the composite trapezoid sum 
If=0; 
for i=1:(N-1) 
    If=If+g(i).*h; 
end; 
If=If+g(1).*h/2+g(N).*h/2; 
If 
+8

這至少是你在這裏問關於你的這個確切的問題第四問題(一些被刪除,所以沒有絕對計數)。 **在進一步詢問之前,請閱讀有關MATLAB編程的入門書。** –

回答

8

ans顯示出來,因爲你叫

LaplaceTransform(bla, blabla) 

代替

LaplaceTransform(bla, blabla); 

你缺少一個分號,當你調用函數)。

exact_answer顯示出來,因爲你行

exact_answer=antiderivative(b,s)-antiderivative(a,s) 

缺少一個分號,以及,你應該有

exact_answer=antiderivative(b,s)-antiderivative(a,s);