0

如何将cputime函数转换为tic toc?

syms x
error = 0;
fun = 0; 
N = 10; 
b = 4; 
a = 0; 
f = (1+x)^(3/2);
f1 = @(y)(1+y)^(3/2);
t = cputime;
fun1 = double(int(f,x,a,b)); 
for N = 10:1000
    fun = 0;
    h = (b-a)/N;
    for i = 0:h:4-h
        fun = fun + (h/2)*(f1(i) + f1(i+h)); 
    end
    error = abs(fun1-fun); 
    if(error < 0.00001)
       break;
    end
end
t = cputime - t; 
fprintf('Approximate Value: %f\n',fun);
fprintf('N Value: %d\n',N);
fprintf('Computation time: %f\n',t);
4

0 回答 0