필터 지우기
필터 지우기

Error with my MATLAB code

조회 수: 7 (최근 30일)
Newbie
Newbie 2023년 3월 1일
답변: Torsten 2023년 3월 1일
Hello everybody, I am creating code in Matlab to calculate the shear relaxation modulus in time domain G(t) from the relaxation modulus E(t) but I cannot run this code and below is the message. Anyone can help me?
Here is my code:
Error using symengineclc
syms t s Gs Gt Ks Es Et
MSU1 = readtable('C:\Users\ADMIN\OneDrive\Documents\Đồ án tốt nghiệp\Relaxation data.xlsx','Range','A4:E82');
E00 = 8567.19;
v = 0.3;
Gt_total = [];
%%Khai báo bộ số E_i và tau_i
E1 = [726.17 0 0];
E2 = [114684.99 0 0];
E3 = [690.51 0 0];
tau1 = [2210.8 0 0];
tau2 = [10.2 0 0];
tau3 = [160.0417 0 0];
value_t = linspace(0,15000,1501);
for i=1:3
Et = E00(i)+E1(i)*exp(-t/tau1(i))+E2(i)*exp(-t/tau2(i))+E3(i)*exp(-t/tau3(i));
%%Biến đổi Laplace để đưa hàm mô-đun nghỉ từ miền thời gian về miền tần số
Et = simplify(laplace(Es, t, s));
%%Thiết lập hàm mô-đun khối trong miền tần số
Ks = E0/(3*s*(1-2*v));
%%Hàm mô-đun nghỉ cắt thông qua mối liên hệ giữa hàm mô-đun nghỉ và hàm mô-đun khối
Gs = ((9*Ks)-Es)/(Es*Ks);
%%Hàm mô-đun nghỉ cắt trong miền thời gian sau khi được biến đổi Laplace
Gt = ilaplace(Gs,t);
Gt = double(subs(Gt,t,value_t));
Gt_total = [Gt_total Gt'];
end
figure(1);
hold on;
grid on;
plot(value_t,Gt_total(:,1),'r','LineWidth',1.5);
plot(value_t,Gt_total(:,2),'g','LineWidth',1.5);
plot(value_t,Gt_total(:,3),'b','LineWidth',1.5);
xlabel('Thời gian (s)');
ylabel('Mô-đun nghỉ cắt G(t)(MPa)');
title('Đồ thị biểu diễn mô-đun nghỉ G(t) theo thời gian cho các tỷ lệ phần trăm sợi khác nhau');
grid on;
writematrix([value_t(:),Gt_total(:,1),Gt_total(:,2),Gt_total(:,3)],'C:\Relaxation modulus\data.xls');
And here is the message:
Unable to convert expression containing symbolic variables into double array. Apply 'subs' function first to substitute values for variables.
Error in sym/double (line 702)
Xstr = mupadmex('symobj::double', S.s, 0);
Error in doantotnghiep (line 25)
Gt = double(subs(Gt,t,value_t));
  댓글 수: 4
Jan
Jan 2023년 3월 1일
@Newbie: Sorry, I meant the data file, not the code. It is useful, if the readers can run the posted code. Then they can test a suggested solution.
Newbie
Newbie 2023년 3월 1일
Here is my data file

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
Image Analyst 2023년 3월 1일
I don't see any need for them to be symbolic variables instead of just regular double variables. What happens if you delete this line?
syms t s Gs Gt Ks Es Et
  댓글 수: 2
Newbie
Newbie 2023년 3월 1일
If I delete that line it still shows:
Error using symengine
Unable to convert expression containing symbolic variables into double array. Apply 'subs' function first to substitute values for variables.
Error in sym/double (line 702)
Xstr = mupadmex('symobj::double', S.s, 0);
Error in doantotnghiep (line 24)
Gt = double(subs(Gt,t,value_t));
Image Analyst
Image Analyst 2023년 3월 1일
Sorry, I don't have the Symbolic Toolbox or the simplify function. Call tech support.

댓글을 달려면 로그인하십시오.


Torsten
Torsten 2023년 3월 1일
E0 and Es are undefined.
syms t s Gs Gt Ks Es Et
MSU1 = readtable('Relaxation data.xlsx','Range','A4:E82');
E00 = 8567.19;
v = 0.3;
Gt_total = [];
%%Khai báo bộ số E_i và tau_i
E1 = [726.17 0 0];
E2 = [114684.99 0 0];
E3 = [690.51 0 0];
tau1 = [2210.8 0 0];
tau2 = [10.2 0 0];
tau3 = [160.0417 0 0];
value_t = linspace(0,15000,1501);
for i=1:3
Et = E00(i)+E1(i)*exp(-t/tau1(i))+E2(i)*exp(-t/tau2(i))+E3(i)*exp(-t/tau3(i));
%%Biến đổi Laplace để đưa hàm mô-đun nghỉ từ miền thời gian về miền tần số
Et = simplify(laplace(Es, t, s));
%%Thiết lập hàm mô-đun khối trong miền tần số
Ks = E0/(3*s*(1-2*v));
%%Hàm mô-đun nghỉ cắt thông qua mối liên hệ giữa hàm mô-đun nghỉ và hàm mô-đun khối
Gs = ((9*Ks)-Es)/(Es*Ks);
%%Hàm mô-đun nghỉ cắt trong miền thời gian sau khi được biến đổi Laplace
Gt = ilaplace(Gs,t);
Gt = double(subs(Gt,t,value_t));
Gt_total = [Gt_total Gt'];
end
Unrecognized function or variable 'E0'.
figure(1);
hold on;
grid on;
plot(value_t,Gt_total(:,1),'r','LineWidth',1.5);
plot(value_t,Gt_total(:,2),'g','LineWidth',1.5);
plot(value_t,Gt_total(:,3),'b','LineWidth',1.5);
xlabel('Thời gian (s)');
ylabel('Mô-đun nghỉ cắt G(t)(MPa)');
title('Đồ thị biểu diễn mô-đun nghỉ G(t) theo thời gian cho các tỷ lệ phần trăm sợi khác nhau');
grid on;
writematrix([value_t(:),Gt_total(:,1),Gt_total(:,2),Gt_total(:,3)],'C:\Relaxation modulus\data.xls');

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by