Filter löschen
Filter löschen

Error with my MATLAB code

7 Ansichten (letzte 30 Tage)
Newbie
Newbie am 1 Mär. 2023
Beantwortet: Torsten am 1 Mär. 2023
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 Kommentare
Jan
Jan am 1 Mär. 2023
@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 am 1 Mär. 2023
Here is my data file

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Image Analyst
Image Analyst am 1 Mär. 2023
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 Kommentare
Newbie
Newbie am 1 Mär. 2023
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 am 1 Mär. 2023
Sorry, I don't have the Symbolic Toolbox or the simplify function. Call tech support.

Melden Sie sich an, um zu kommentieren.


Torsten
Torsten am 1 Mär. 2023
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');

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by