Clear Filters
Clear Filters

Undefined function 'mtimes' in line 56

1 view (last 30 days)
Line 56 (M = (m/-dt)-(qdot/(dens*dx*cp))*dx-(h*dx/(dens*dx*cp))*Tinf;) creates a 'mtimes' error and evrything I can find says this has to do with multiplying function handles, but I don't have any function handles anywhere in the code.
cp = 1007;
dens = 1.18;
k = 60;
h = 100;
dx = 0.01;
dt = 0.1;
endTime = 50;
qdot = 1000;
alpha = 3.243*10^-5;
F = alpha * dt / dx^2;
C = 0.05;
Bi = (h*C)/k;
Tinf = 27;
T2 = 20;
T = zeros(4, 5);
Z = dens*dx*cp;
Y = (1+2*F*(2+Bi));
Coef = 2*Bi*F*Tinf;
CoefBottom = 2*Bi*F*T2;
Y2 = 1+4*F;
Q = 1-4*k*Z;
Q2 = 2*qdot*Z*dx;
U = ((-h*dx/Z)-(2*k/Z)-(1/dt));
R = (1+4*F*(1+Bi));
numTimeSteps = ceil(endTime / dt);
for t = 1:numTimeSteps
Tnew = T;
A = [U k/Z 0 0 0 k/Z 0 0 0 0 0 0 0 0 0 0 0 0 0 0,%1
k*Z Q k*Z 0 0 0 2*k*Z 0 0 0 0 0 0 0 0 0 0 0 0 0,%2
0 k*Z Q k*Z 0 0 0 2*k*Z 0 0 0 0 0 0 0 0 0 0 0 0,%3
0 0 k*Z Q k*Z 0 0 0 2*k*Z 0 0 0 0 0 0 0 0 0 0 0,%4
0 0 0 k/Z U 0 0 0 0 k/Z 0 0 0 0 0 0 0 0 0 0,%5
-F 0 0 0 0 Y -2*F 0 0 0 0 -F 0 0 0 0 0 0 0 0,%6
0 -F 0 0 0 -F Y2 -F 0 0 0 -F 0 0 0 0 0 0 0 0,%7
0 0 -F 0 0 0 -F Y2 -F 0 0 0 -F 0 0 0 0 0 0 0,%8
0 0 0 -F 0 0 0 -F Y2 -F 0 0 0 -F 0 0 0 0 0 0,%9
0 0 0 0 -F 0 0 0 -2*F Y 0 0 0 0 -F 0 0 0 0 0,%10
0 0 0 0 0 -F 0 0 0 0 Y -2*F 0 0 0 0 -F 0 0 0,%11
0 0 0 0 0 0 -F 0 0 0 -F Y2 -F 0 0 0 -F 0 0 0,%12
0 0 0 0 0 0 0 -F 0 0 0 -F Y2 -F 0 0 0 -F 0 0,%13
0 0 0 0 0 0 0 0 -F 0 0 0 -F Y2 -F 0 0 0 -F 0,%14
0 0 0 0 0 0 0 0 0 -F 0 0 0 -2*F Y 0 0 0 0 -F,%15
0 0 0 0 0 0 0 0 0 0 -2*F 0 0 0 0 R -2*F 0 0 0,%16
0 0 0 0 0 0 0 0 0 0 0 -2*F 0 0 0 -F Y -F 0 0,%17
0 0 0 0 0 0 0 0 0 0 0 0 -2*F 0 0 0 -F Y -F 0,%18
0 0 0 0 0 0 0 0 0 0 0 0 0 -2*F 0 0 0 -F Y -F,%19
0 0 0 0 0 0 0 0 0 0 0 0 0 0 -2*F 0 0 0 -2*F R];%20
m = T(1,1);
n = T(1,5);
M = (m/-dt)-(qdot/(dens*dx*cp))*dx-(h*dx/(dens*dx*cp))*Tinf;
N = (n/-dt)-(qdot/(dens*dx*cp))*dx-(h*dx/(dens*dx*cp))*Tinf;
B = [M,
-T(1,2)-Q2,
-T(1,3)-Q2,
-T(1,4)-Q2,
N,
Coef+T(2,1),
T(2,2),
T(2,3),
T(2,4),
Coef+T(2,5),
Coef+T(1,3),
T(3,2),
T(3,3),
T(3,4),
Coef+T(3,5),
2*CoefBottom+T(1,4),
CoefBottom+T(4,2),
CoefBottom+T(4,3),
CoefBottom+T(4,4),
2*CoefBottom+T(4,5)];
C = A^-1 * B;
Tnew = [C(1) C(2) C(3) C(4) C(5),
C(6) C(7) C(8) C(9) C(10),
C(11) C(12) C(13) C(14) C(15),
C(16) C(17) C(18) C(19) C(20)];
T = Tnew;
h = imagesc(T);
title(['Time = ' num2str(t*dt) ' ']);
colorbar;
axis equal;
xlabel('X-axis');
ylabel('Y-axis');
drawnow;
end
Operator '*' is not supported for operands of type 'matlab.graphics.primitive.Image'.

Accepted Answer

Walter Roberson
Walter Roberson on 14 Nov 2023
h = 100;
h is numeric.
M = (m/-dt)-(qdot/(dens*dx*cp))*dx-(h*dx/(dens*dx*cp))*Tinf;
You do calculations with h inside the loop.
h = imagesc(T);
But now h is the handle to the image() object that is created by imagesc().
Next iteration will try to multiply the handle to the image object, by numeric values... but that is going to fail.

More Answers (1)

atharva
atharva on 14 Nov 2023
Hey teag,
I understand that you are facing the error "Operator '*' is not supported for operands of type 'matlab.graphics.primitive.Image'."
The error you are encountering is due to the fact that while looping you are trying to add a value to the handle h, which is already an image object created by the imagesc function. To fix this, you should use a different variable for the temperature distribution plot and avoid overwriting it with the image handle.
Here is the code you can try
cp = 1007;
dens = 1.18;
k = 60;
h = 100;
dx = 0.01;
dt = 0.1;
endTime = 50;
qdot = 1000;
alpha = 3.243*10^-5;
F = alpha * dt / dx^2;
C = 0.05;
Bi = (h*C)/k;
Ttinf = 27;
T2 = 20;
T = zeros(4, 5);
Z = dens*dx*cp;
Y = (1+2*F*(2+Bi));
Coef = 2*Bi*F*Ttinf;
CoefBottom = 2*Bi*F*T2;
Y2 = 1+4*F;
Q = 1-4*k*Z;
Q2 = 2*qdot*Z*dx;
U = ((-h*dx/Z)-(2*k/Z)-(1/dt));
R = (1+4*F*(1+Bi));
numTimeSteps = ceil(endTime / dt);
for t = 1:numTimeSteps
Tnew = T;
A = [U k/Z 0 0 0 k/Z 0 0 0 0 0 0 0 0 0 0 0 0 0 0,%1
k*Z Q k*Z 0 0 0 2*k*Z 0 0 0 0 0 0 0 0 0 0 0 0 0,%2
0 k*Z Q k*Z 0 0 0 2*k*Z 0 0 0 0 0 0 0 0 0 0 0 0,%3
0 0 k*Z Q k*Z 0 0 0 2*k*Z 0 0 0 0 0 0 0 0 0 0 0,%4
0 0 0 k/Z U 0 0 0 0 k/Z 0 0 0 0 0 0 0 0 0 0,%5
-F 0 0 0 0 Y -2*F 0 0 0 0 -F 0 0 0 0 0 0 0 0,%6
0 -F 0 0 0 -F Y2 -F 0 0 0 -F 0 0 0 0 0 0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
C(11) C(12) C(13) C(14) C(15),
C(16) C(17) C(18) C(19) C(20)];
T = Tnew;
temp = imagesc(T);
title(['Time = ' num2str(t*dt) ' ']);
colorbar;
axis equal;
xlabel('X-axis');
ylabel('Y-axis');
drawnow;
end
I hope this helps!

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!