error "Inner matrix dimensiion must Agree"

1 view (last 30 days)
Maduka
Maduka on 17 Dec 2022
Commented: DGM on 23 Dec 2022
Please I'm trying to plot graphs and varying parameter Gr and t which is temperature. But i keep getting an error "Inner matrix dimensiion must Agree"
>> Gr = [5:5:25];
>> t = [0.2:0.2:1];
>> H = 1;
>> n = 1;
>> N = 5;
>> Pr = 0.72;
>> S = 0.2;
% This is my code
>> U = -Gr*(t.^2/2 + Pr*(N-n)*(t.^4/24 - t.^2/4) + (Pr*(N-n))^2*(t.^6/720 - t.^4/48 + 5*t.^2)...
+ (Pr*(N-n))^3*(t.^8/40320 - t.^6/1440 + 5*t.^4/576 - 61*t.^2/1440) + (Pr*(N-n))^4*(t.^10/36288000 - t.^8/80640 + 5*t.^6/17280 -61*t.^4/17280 + 1385*t.^2/806400)...
- 1/2 + Pr*(N-n)*5/24 - (Pr*(N-n))^2*61/720 + (Pr*(N-n))^3*277/8064 - (Pr*(N-n)^4*(0.014))...
-(S + H - n)*Gr*(t.^4/24 * Pr*(N-n)*(t.^6/720 - t.^4/48) + (Pr*(N - n))^2*(t.^8/40320 - t.^6/1440 + 5*t.^4/576)...
+ (Pr*(N-n))^3*(t.^10/32688000 - t.^8/80640 + 5*t.^6/17280 + 61*t.^4/17280) + (Pr*(N-n))^4*(t.^12/479001600 - t.^10/7257600 + 5*t.^8/967680 - 61*t.^6/518400 + 1385*t.^4/967680)...
- t.^2/4 + Pr*(N-n)*5*t.^2/48 - (Pr*(N-n))^2*61*t.^2/1440 + (Pr*(N-n))^3*277*t.^2/16128 - (Pr*(N-n))^4*(7*t.^2/1000))...
-(1/24 + Pr*(N-n)*(1/720 -1/48) + (Pr*(N-n))^2*(1/40320 - 1/1440 + 5/576) + (Pr*(N-n))^3*(1/36288000 - 1/80640 + 5/17280 - 61/17280) + (Pr*(N-n))^4*(1/479001600 - 1/7257600 + 5/967680 - 61/518400 + 1385/967680)...)
-1/4 + Pr*(N-n)*5/48 - (Pr*(N-n))^2*61/1440 + (Pr*(N-n))^3*277/16128-(Pr*(N-n))^4*(7/100)))
Error using *
Inner matrix dimensions must agree.
>>
>>

Accepted Answer

DGM
DGM on 17 Dec 2022
Edited: DGM on 17 Dec 2022
You're trying to do matrix multiplication with arrays of incompatible size. You probably mean to do .* elementwise multiplication.
Also, those exponentiations are probably all wrong as well. For example:
1^2/3
ans = 0.3333
1^(2/3)
ans = 1
EDIT: also, this improperly-continued line means that the trailing ) isn't being used. Since the parentheses are balanced, that means that another parentheses is either added or missing somewhere. It's impossible to know where.
+ A^3*(1/36288000 - 1/80640 + 5/17280 - 61/17280) + A^4*(1/479001600 - 1/7257600 + 5/967680 - 61/518400 + 1385/967680)...)
  10 Comments
Maduka
Maduka on 23 Dec 2022
N = [5:5:10 20:30:80];
t = (0:0.2:1).';
U = [0 0 0 0 0;
-0.203 -0.2045 -0.2094 -0.2248 -0.2411;
-0.8334 -0.8742 -0.9593 -1.2573 -1.6266;
-1.9722 -2.1899 -2.6840 -4.737 -7.9306;
-3.7592 -4.51 -6.3789 -16.1119 -35.5583;
-6.4136 -8.4597 -14.1636 -52.4222 -148.671];
hp = plot(t,U,'-');
lstr = cell(numel(N),1);
title('Effect of Radiation on Velocity')
for k = 1:numel(N)
lstr{k} = sprintf('N = %d',N(k));
end
legend(hp,lstr,'location','southwest')
On this plot, how do I convert those lines to curves, so the sharp points won't be noticed
DGM
DGM on 23 Dec 2022
If you just want to smooth the curve and still have it go through the original points, you can do some sort of spline interpolation.
N = [5:5:10 20:30:80];
torig = (0:0.2:1).'; % original t
U = [0 0 0 0 0;
-0.203 -0.2045 -0.2094 -0.2248 -0.2411;
-0.8334 -0.8742 -0.9593 -1.2573 -1.6266;
-1.9722 -2.1899 -2.6840 -4.737 -7.9306;
-3.7592 -4.51 -6.3789 -16.1119 -35.5583;
-6.4136 -8.4597 -14.1636 -52.4222 -148.671];
% interpolate U using a finer t
t = (0:0.05:1).';
U = interp1(torig,U,t,'spline'); % use spline interpolation to smooth the curve
hp = plot(t,U,'-');
lstr = cell(numel(N),1);
title('Effect of Radiation on Velocity')
for k = 1:numel(N)
lstr{k} = sprintf('N = %d',N(k));
end
legend(hp,lstr,'location','southwest')

Sign in to comment.

More Answers (1)

Torsten
Torsten on 17 Dec 2022
GR = [5:5:25];
T = [0.2:0.2:1];
H = 1;
n = 1;
N = 5;
Pr = 0.72;
S = 0.2;
for i = 1:numel(GR)
Gr = GR(i);
for j = 1: numel(T)
t = T(j);
U(i,j) = -Gr*(t.^2/2 + Pr*(N-n)*(t.^4/24 - t.^2/4) + (Pr*(N-n))^2*(t.^6/720 - t.^4/48 + 5*t.^2)...
+ (Pr*(N-n))^3*(t.^8/40320 - t.^6/1440 + 5*t.^4/576 - 61*t.^2/1440) + (Pr*(N-n))^4*(t.^10/36288000 - t.^8/80640 + 5*t.^6/17280 -61*t.^4/17280 + 1385*t.^2/806400)...
- 1/2 + Pr*(N-n)*5/24 - (Pr*(N-n))^2*61/720 + (Pr*(N-n))^3*277/8064 - (Pr*(N-n)^4*(0.014))...
-(S + H - n)*Gr*(t.^4/24 * Pr*(N-n)*(t.^6/720 - t.^4/48) + (Pr*(N - n))^2*(t.^8/40320 - t.^6/1440 + 5*t.^4/576)...
+ (Pr*(N-n))^3*(t.^10/32688000 - t.^8/80640 + 5*t.^6/17280 + 61*t.^4/17280) + (Pr*(N-n))^4*(t.^12/479001600 - t.^10/7257600 + 5*t.^8/967680 - 61*t.^6/518400 + 1385*t.^4/967680)...
- t.^2/4 + Pr*(N-n)*5*t.^2/48 - (Pr*(N-n))^2*61*t.^2/1440 + (Pr*(N-n))^3*277*t.^2/16128 - (Pr*(N-n))^4*(7*t.^2/1000))...
-(1/24 + Pr*(N-n)*(1/720 -1/48) + (Pr*(N-n))^2*(1/40320 - 1/1440 + 5/576) + (Pr*(N-n))^3*(1/36288000 - 1/80640 + 5/17280 - 61/17280) + (Pr*(N-n))^4*(1/479001600 - 1/7257600 + 5/967680 - 61/518400 + 1385/967680)...)
-1/4 + Pr*(N-n)*5/48 - (Pr*(N-n))^2*61/1440 + (Pr*(N-n))^3*277/16128-(Pr*(N-n))^4*(7/100)));
end
end
contourf(GR,T,U)
colorbar
  3 Comments
Maduka
Maduka on 18 Dec 2022
Please can you help me structure it better?
Maduka
Maduka on 18 Dec 2022
@DGM please can you help structure the code, this is the nature of graph I’m expecting

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2014a

Community Treasure Hunt

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

Start Hunting!