clear all
clc
k=1;
z3=[0.21,0.132,0.094,0.073,0.0601,0.0509];
b3=[4.7293,7.8532,10.9912,14.1372,17.2788,20.4204];
syms x
a=1/(4*b3(k)^3*(1-cosh(b3(k))*cos(b3(k))));
t1=sinh(b3(k)*x)+sin(b3(k)*x);
t2=cosh(b3(k)*x)+cos(b3(k)*x);
% first part of green function
s1=subs(t1,x,(1-z3(k)));
s2=subs(t2,x,(1-z3(k)));
m1=(cosh(b3(k))-cos(b3(k)))*((t1*s2)+(t2*s1));
m2=sinh(b3(k))*((t1*s1)+(t2*s2));
m3=sin(b3(k))*((t1*s1)-(t2*s2));
w1=a*(m1-m2-m3);
w1= matlabFunction(w1)
% second part of green function
s3=subs(t1,x,z3(k));
s4=subs(t1,x,(1-x));
s5=subs(t2,x,z3(k));
s6=subs(t2,x,(1-x));
n1=(cosh(b3(k))-cos(b3(k)))*((s3*s6)+(s5*s4));
n2=sinh(b3(k))*((s3*s4)+(s5*s6));
n3=sin(b3(k))*((s3*s4)-(s5*s6));
w2=a*(n1-n2-n3);
w2= matlabFunction(w2)
x=0:0.01:1;
c=0:0.01:1;
for i=1:length(x)
if (x(i)<=z3(k))
w(i)=w1;
% below is the second half of the green function
elseif (x(i)>=z3(k))
w(i)=w2;
end
end
plot(x,w)
我有一个符号表达式,我想指定x的值,它是一个向量, 并提取分段的“w”。我发现解决这个问题有些困难。“不允许非标量的函数句柄数组”是我得到的错误。
答案 0 :(得分:1)
第一个w1
和w2
不是符号表达式,而是普通的匿名函数句柄。因此,我想您只想将x(i)
插入w1
或w2
,对吗?
其次,在行x=0:0.01:1;
中,您正在创建一个双精度数组x
并覆盖先前定义的符号变量syms x
,后者将成为符号句柄的函数参数。在这种情况下没有任何反应,但我建议重命名矢量。
X=0:0.01:1;
for ii=1:length(xX)
if (X(ii)<=z3(k))
w(ii) = w1(X(ii));
% below is the second half of the green function
elseif (x(ii)>=z3(k))
w(ii)=w2(X(ii));
end
end
在您将句柄分配给w
之前,需要一个单元格数组。但我怀疑你是否想要那个。