matlab third homework


matlab工程分析第三次作业

% 3.5
n = 0:1:15;
Fn = 1/sqrt(5)*(((1+sqrt(5))/2).^n-((1-sqrt(5))/2).^n);
fprintf(1,'F%2.0f= %.0f\n',[n;Fn])
disp([repmat('F',16,1) num2str(n','%2.0f') repmat('=',16,1) num2str(Fn','%.0f')])
F 0= 0
F 1= 1
F 2= 1
F 3= 2
F 4= 3
F 5= 5
F 6= 8
F 7= 13
F 8= 21
F 9= 34
F10= 55
F11= 89
F12= 144
F13= 233
F14= 377
F15= 610
F 0=  0
F 1=  1
F 2=  1
F 3=  2
F 4=  3
F 5=  5
F 6=  8
F 7= 13
F 8= 21
F 9= 34
F10= 55
F11= 89
F12=144
F13=233
F14=377
F15=610
% 3.8
n = input('Enter an integer < 12:');
nn = 1:1:n;
Fn = factorial(nn);
fprintf(1,'For n=%.0f, %.0f!=%.0f\n',[nn;nn;Fn])

  File F:\Matlab 2017a\toolbox\matlab\external\engines\engine_api\+matlab\+internal\+engine\input.m, line 20, in input
'input' command is not supported for MATLAB launched by Engine without Desktop.


% 4.4
x0 = 1.5;
t0 = 1e-8;
fx = cos(x0) + sin(x0);
fx1 = -sin(x0) + cos(x0);
cnt = 0
while abs(fx) >= t0
    x0 = x0 - fx/fx1;
    fx = cos(x0) + sin(x0);
    fx1 = -sin(x0) + cos(x0);
    cnt=cnt+1;
end
fprintf('At x = %.7f, f(x)=%g after %.0f iterations',[x0 fx cnt])
cnt =

     0

At x = 2.3561945, f(x)=1.11022e-16 after 4 iterations
% 4.8
n = input('Please input N<10:');
H = zeros(n,n);
for i=1:n
    for j=1:n
        if i+j-1>n
            H(i,j) = 0;
        else
            H(i,j) = i+j-1;
        end
    end
end
H =

     1     2     3     4
     2     3     4     0
     3     4     0     0
     4     0     0     0
% 4.12a
a = 7;
x0 = 3;
x1 = 0.5*(x0 + a/x0);
cnt = 1;
while 1
    if abs(x1-x0)<1e-6
        break
    else
        cnt = cnt + 1;
        x0 = x1;
        x1 = 0.5*(x1 + a/x1);
    end
end
cnt
cnt =

     4
% 4.12b
a = 7;
x0 = 100;
x1 = 0.5*(x0 + a/x0);
cnt = 1;
while 1
    if abs(x1-x0)<1e-6
        break
    else
        cnt = cnt + 1;
        x0 = x1;
        x1 = 0.5*(x1 + a/x1);
    end
end
cnt
cnt =

    10
sum([2,3,4])
ans =

     9
% 4.16i
x = [1,7,8,6,5,7,3,5,4];
e = [2,6,10,4,3,6,1,2,3];
n = length(x);
eM = [];
xM = [];
i = 1;
while i<=n
    signe = e(1,i);
    signx = x(1,i);
    while 1
        if signe<5
            i=i+1;
            if i > n
                break
            else
                signe = signe + e(1,i);
                signx = signx + x(1,i);
            end
        end
        if signe>=5 & sum(e(1,i+1:n))<5
            signe = signe + sum(e(1,i+1:n));
            signx = signx + sum(x(1,i+1:n));
            i = n+1;
        end
        if signe>=5;
            break
        end
    end
    eM = [eM signe];
    xM = [xM signx];
    i = i + 1;
end
eM
xM
X_2 = sum((xM-eM).^2./eM)
eM =

     8    10     7     6     6


xM =

     8     8    11     7    12


X_2 =

    8.8524
% 4.16i
x = [7,11,13,6];
e = [6,10,15,7];
n = length(x);
eM = [];
xM = [];
i = 1;
while i<=n
    signe = e(1,i);
    signx = x(1,i);
    while 1
        if signe<5
            i=i+1;
            if i > n
                break
            else
                signe = signe + e(1,i);
                signx = signx + x(1,i);
            end
        end
        if signe>=5 & sum(e(1,i+1:n))<5
            signe = signe + sum(e(1,i+1:n));
            signx = signx + sum(x(1,i+1:n));
            i = n+1;
        end
        if signe>=5;
            break
        end
    end
    eM = [eM signe];
    xM = [xM signx];
    i = i + 1;
end
eM
xM
X_2 = sum((xM-eM).^2./eM)
eM =

     6    10    15     7


xM =

     7    11    13     6


X_2 =

    0.6762
% 4.16i
x = [3,14,20,25,14,6,2,0,1,0];
e = [4,12,19,19,14,8,4,2,1,1];
n = length(x);
eM = [];
xM = [];
i = 1;
while i<=n
    signe = e(1,i);
    signx = x(1,i);
    while 1
        if signe<5
            i=i+1;
            if i > n
                break
            else
                signe = signe + e(1,i);
                signx = signx + x(1,i);
            end
        end
        if signe>=5 & sum(e(1,i+1:n))<5
            signe = signe + sum(e(1,i+1:n));
            signx = signx + sum(x(1,i+1:n));
            i = n+1;
        end
        if signe>=5;
            break
        end
    end
    eM = [eM signe];
    xM = [xM signx];
    i = i + 1;
end
eM
xM
X_2 = sum((xM-eM).^2./eM)
eM =

    16    19    19    14     8     8


xM =

    17    20    25    14     6     3


X_2 =

    5.6349

文章作者: lovelyfrog
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 lovelyfrog !
 上一篇
编辑器,服务器 编辑器,服务器
编辑器,服务器 gedit 编辑器类似于windows下的写字板程序,在不需要特别复杂的编程环境下可以使用 sublime跨平台 编辑器之神-Vimvi有三种基本工作模式: 命令模式 文本输入模式 末行模式 命令行模式不管处于何种模式
2017-10-30
下一篇 
matlab second homework matlab second homework
matlab工程分析第二次作业 % 2.3 %a y = [0,-0.2,0.4,-0.6,0.8,-1.0,-1.2,-1.4,1.6]; z = sin(y); nz = z(find(z<0)); min_nz = min(
2017-10-02
  目录