error "Inner matrix dimensiion must Agree"

조회 수: 4 (최근 30일)
Maduka
Maduka 2022년 12월 17일
댓글: DGM 2022년 12월 23일
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.
>>
>>

채택된 답변

DGM
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
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
Maduka
Maduka 2022년 12월 23일
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 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
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
  댓글 수: 3
Maduka
Maduka 2022년 12월 18일
Please can you help me structure it better?
Maduka
Maduka 2022년 12월 18일
@DGM please can you help structure the code, this is the nature of graph I’m expecting

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by