我很努力地将符合我的土木工程项目要求的函数从符号表达式转换为函数。我需要使用fzero
来查找函数的根。这里H
应该是变量,我需要找出H
的值。该功能是这样将符号表达式转换为Matlab中的函数句柄R2013b
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
文件中的主要文件,其中我会找到这个方程的根。 有人可以指导我如何做到这一点?
我已经尝试使用下面的代码,但我没有成功。
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 [email protected](H) (H/EAo)*s;
x_c [email protected](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 [email protected](H) (x_c(H) + ...
+ C1(H)*asinh((qc*sk - VA + sum_Fj)/H) + ...
- C1(H)*asinh((qc*sk_1 - VA + sum_Fj)/H));
end
编辑:
我要解决的主要文件中的以下公式:
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.
因此,在主文件中,我写这样的:
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);
怎么样matlabFunction:HTTP://www.mathworks.com/help/symbolic/matlabfunction.html – 2014-12-02 14:49:32
@ Benoit_11我Matlab的R2013b。我猜这个功能在这个版本中不起作用。 – 2014-12-02 14:51:39
尝试调用'fzero'在哪里?你想要解决什么功能?我实际上没有看到任何符号数学。你只是想解决整个第一个功能?然后使用@f_x_c。但我也注意到在这个函数中'H'是未定义的。参数是'H0'。 – Peter 2014-12-02 14:53:11