m0_53140879 2021-06-11 18:40 采纳率: 100%
浏览 36
已采纳

有大佬知道这个matlab代码哪里错了么?

f=@(x,y)h-3.086*(x^2)-20.4082*(y^2);
q=integral2(f,-1/(30.864)^(1/2),1/(30.864)^(1/2),-1/(204.082)^(1/2),1/(204.082)^(1/2));

  • 写回答

3条回答 默认 最新

  • CSDN专家-Matlab_Fans 2021-06-11 19:07
    关注

    1. 需要给h赋值;

    2. f函数中针对x和y的^操作需要改成 .^

    h = 1;
    f=@(x,y) h-3.086*(x.^2)-20.4082*(y.^2);
    q=integral2(f,-1/(30.864)^(1/2),1/(30.864)^(1/2),-1/(204.082)^(1/2),1/(204.082)^(1/2))

    结果:

    q =
    
        0.0470
    

     

    已知q求h的办法,下面的函数文件存成funq.m文件

    function q = funq(h)
    f=@(x,y) h-3.086*(x.^2)-20.4082*(y.^2);
    q=integral2(f,-1/(30.864)^(1/2),1/(30.864)^(1/2),-1/(204.082)^(1/2),1/(204.082)^(1/2));
    

    求解m脚本文件

    q = 0.5;
    f = @(h) funq(h)-q;
    h0 = 1;
    h = fsolve( f,h0  )

    结果:

    Equation solved.
    
    fsolve completed because the vector of function values is near zero
    as measured by the value of the function tolerance, and
    the problem appears regular as measured by the gradient.
    
    <stopping criteria details>
    
    h =
    
        9.9873

    验算:

    >> f(h)
    
    ans =
    
       2.0365e-09
    
    >> funq(h)
    
    ans =
    
        0.5000
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?