error "Inner matrix dimensiion must Agree"
2 次查看(过去 30 天)
显示 更早的评论
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.
>>
>>
0 个评论
采纳的回答
DGM
2022-12-17
编辑:DGM
2022-12-17
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
1^(2/3)
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 个评论
DGM
2022-12-23
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')
更多回答(1 个)
Torsten
2022-12-17
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!