在Matlab R2013b中将符号表达式转换为函数句柄 [英] Converting symbolic expression to function handle in Matlab R2013b

查看:104
本文介绍了在Matlab R2013b中将符号表达式转换为函数句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力从符号表达式转换我的土木工程项目所需的功能.我需要使用fzero来找到函数的根.在这里H应该是变量,我需要找出H的值.功能就像

I am struggling to convert a function, which I require for my civil engineering project, from symbolic expression. I need to use fzero to find the root of the function. Here H should be the variable and I need to find out the value of H. The function goes like

function x_c = f_x_c(s,H0,VA,Lo,qc,EAo,NF,Sj,Fj)

if (s < 0) || (s > Lo)
    disp('The value of s is invalid')
    disp(['s = ' num2str(s)]);
    return
end


C1 = H/qc;
if NF == 0
    n = 0;
    sn = 0;
    sum_Fj = 0;
end


if NF >= 1
    Sj_Q = [0; Sj; Lo];
    %Determine n and sn if 0 <= s < Lo:
    if s < Lo
        STOP = 0;
        k = 0;
        while STOP == 0
            k = k + 1;
            if (s >= Sj_Q(k,1)) && (s < Sj_Q((k + 1),1))
                STOP = 1;
            end
        end
        n = k - 1;
        sn = Sj_Q(k,1);
    end
    %Determine n and sn if s = Lo:
    if s == Lo
        n = NF;
        sn = Sj(NF,1);
    end
    sum_Fj = sum(Fj(1:n,1));
end


x_c = (H/EAo)*s;
x_c = x_c + C1*asinh((qc*s - VA + sum_Fj)/H) + ...
    - C1*asinh((qc*sn - VA + sum_Fj)/H);


for j = 1:n
    sk = Sj_Q((j + 1),1);
    sk_1 = Sj_Q(j,1);
    sum_Fj = sum(Fj(1:(j - 1)));


    x_c = x_c + ...
        + C1*asinh((qc*sk - VA + sum_Fj)/H) + ...
        - C1*asinh((qc*sk_1 - VA + sum_Fj)/H);

end

我想在主文件中使用此f_x_c.m文件,在该文件中我将找到等式的根. 有人可以指导我该怎么做吗?

I want to use this f_x_c.m file in the main file where I will find the roots of this equation. Could someone guide me how I can do that?

我尝试使用以下代码进行操作,但未成功.

I have tried doing it using the following code but I wasn't successful.

if (s < 0) || (s > Lo)
    disp('The value of s is invalid')
    disp(['s = ' num2str(s)]);
    return
end

C1 = @(H) (H/qc);
if NF == 0
    n = 0;
    sn = 0;
    sum_Fj = 0;
end


if NF >= 1
    Sj_Q = [0; Sj; Lo];
    %Determine n and sn if 0 <= s < Lo:
    if s < Lo
        STOP = 0;
        k = 0;
        while STOP == 0
            k = k + 1;
            if (s >= Sj_Q(k,1)) && (s < Sj_Q((k + 1),1))
                STOP = 1;
            end
        end
        n = k - 1;
        sn = Sj_Q(k,1);
    end
    %Determine n and sn if s = Lo:
    if s == Lo
        n = NF;
        sn = Sj(NF,1);
    end
    sum_Fj = sum(Fj(1:n,1));
end


x_c =@(H) (H/EAo)*s;
x_c =@(H) (x_c(H) + (C1(H))*asinh((qc*s - VA + sum_Fj)/H) + ...
    - (C1(H))*asinh((qc*sn - VA + sum_Fj)/H));


for j = 1:n
    sk = Sj_Q((j + 1),1);
    sk_1 = Sj_Q(j,1);
    sum_Fj = sum(Fj(1:(j - 1)));


    x_c =@(H) (x_c(H) + ...
        + C1(H)*asinh((qc*sk - VA + sum_Fj)/H) + ...
        - C1(H)*asinh((qc*sk_1 - VA + sum_Fj)/H));

end

我想在主文件中求解以下方程式:

I want to solve the following equation in the main file:

equation = f_x_c(inext_length, H0, vertical_reaction, inext_length, qc, EAo, NF, hanger_arc_length, point_hanger_force) + 1400;
% Whatever equation f_x_c returns, I have to add another number to it(like here it is 1400), then solve this equation using fzero.

因此,在主文件中,我这样写:

So, in the main file, I wrote like:

equation = @(H) f_x_c(inext_length, H0, vertical_reaction, inext_length, qc, EAo, NF, hanger_arc_length, point_hanger_force);

equation = @(H) (equation(H) + 1400);
answer = fsolve(equation, H0);

推荐答案

对您问题的模拟答案可能类似于

A mock answer to your question probably looks like

function x_c = f_x_c(H,A,B,C,D)
    x_c = H*A;
    x_c = x_c + B*asinh(C/H) - B*asinh(D/H);
end

而对求解器的调用是

H = fzero(@(H)(f_x_c(H,1,1,1,1)+1400),1);

这篇关于在Matlab R2013b中将符号表达式转换为函数句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆