發新話題
打印

能用軟體解決微積分問題嗎?

能用軟體解決微積分問題嗎?

比如:
f(x)=e^x;
在2到3之間的積分

TOP

引用:
(a)  A=[1 1 1;1 1.00001 1.00001];
      [Q,d]=eig(A*A')


(c)  answer = svd(A*A')

(d)  X=pinv( A)

(e)  answer = svd( A )

(f)  A=[1 1 1;1 1.00001 1.00001];
        b=[3 ; 2.00001];

        x = lscov(A,b)
是作業吧大大
給你
引用:
function test2
%前置處理
clear;

%共用初始設定
interval=[2,3];
step_size=0.1;
h=step_size;
a=interval(1);
b=interval(2);

%初始設定
steps=(b-a)/h+2;
for counter1=1:steps
    x1(counter1)=a+counter1*h-0.1;
end
y1(1:steps)=0;
%實作
for counter1=1:steps
    f1(counter1)=(h/2)*(exp(a+h*counter1-0.1)+exp(a+h*counter1));
end
y1(1)=f1(1);
for counter1=2:steps
    y1(counter1)=f1(counter1)+y1(counter1-1);
end
%繪圖
subplot(2,3,1);
plot(x1,y1,'-o');
axis([2 3 0 15]);
set(gca, 'xtick', [2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0]);
set(gca, 'ytick', [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]);
xlabel('x');
ylabel('y');
title('Tra法');
grid on;

%初始設定
steps=(b-a)/h+2;
for counter2=1:steps/2
    x2(counter2)=a+2*counter2*h-0.2;
end
y2(1:steps/2)=0;
%實作
for counter2=1:steps
        f1(counter2)=(h/3)*(exp(a+h*counter2-0.1)+4*exp(a+h*counter2)+exp(a+h*counter2+0.1));
end
temp2(1)=f1(1);
for counter2=3:steps
    if(mod(counter2,2)==1)
        temp2(counter2)=f1(counter2)+temp2(counter2-2);
    end
end
y2(1)=temp2(1);
y2(2)=temp2(3);
y2(3)=temp2(5);
y2(4)=temp2(7);
y2(5)=temp2(9);
y2(6)=temp2(11);
%繪圖
subplot(2,3,2);
plot(x2,y2,'-o');
axis([-inf 3 0 15]);
set(gca, 'xtick', [2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0]);
set(gca, 'ytick', [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]);
xlabel('x');
ylabel('y');
title('Sim法');
grid on;

%初始設定
steps=(b-a)/h;
for counter2=1:steps/2
    x3(counter2)=a+3*counter2*h-0.3;
end
y3(1:steps/2)=0;
%實作
for counter2=1:steps*2
        f1(counter2)=(3*h/8)*(exp(a+h*counter2-0.1)+3*exp(a+h*counter2)+3*exp(a+h*counter2+0.1)+exp(a+h*counter2+0.2));
end
temp(1)=f1(1);
for counter2=4:steps*2
    if(mod(counter2,3)==1)
        temp(counter2)=f1(counter2)+temp(counter2-3);
    end
end
y3(1)=temp(1);
y3(2)=temp(4);
y3(3)=temp(7);
y3(4)=temp(10);
y3(5)=temp(13);
%繪圖
subplot(2,3,3);
plot(x3,y3,'-o');
axis([2 3 0 15]);
set(gca, 'xtick', [2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0]);
set(gca, 'ytick', [0 3 6 9 12 15 18 21 24 27 30 33 36 39 42]);
xlabel('x');
ylabel('y');
title('Sim法');
grid on;

%綜合比較
subplot(2,1,2);
plot(x1,y1,'-*',x2,y2,'-x',x3,y3,'-o');
axis([2 3 0 18]);
set(gca, 'xtick', [2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0]);
set(gca, 'ytick', [0 3 6 9 12 15 18 21]);
xlabel('x');
ylabel('y');
title('綜合比較');
legend('T法','S法','S法');
grid on;
end
[ 本帖最後由 h.man 於 2011-3-29 12:59 編輯 ]

TOP

發新話題