Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error using ./ Matrix dimensions must agree

Tags:

matlab

i'm trying to plot this code , with t,x,l variables ...

i'm getting this error "Error using ./ Matrix dimensions must agree.

Error in Uentitled5 (line 16) a=cos(Lambda1.*(x./L));"

t=1:0.5:300;
x=0:0.1:100;
L=0:0.3:100;
Bi=0.01;
A1=1.0017
Lambda1=0.0998
a=cos(Lambda1.*(x./L));
theta=(A1.*exp(-(Lambda1.^2).*t).*a);
for i=t
    plot(t,theta,'-') 
    for j=x
        plot (x,theta,'-','green')
    end
    for k=L
        plot (L,theta,'-','red')
    end
end
title('Dimensionless Temperature for Plane Wall  ')
xlim([0 2])
ylim([0 350])
xlabel('\Theta(0)')
ylabel('t(Time in Seconds)')
like image 325
Mohamed Maher Avatar asked May 08 '26 00:05

Mohamed Maher


1 Answers

The three vectors you are using, x, t, and L must have the same number of elements. You can fix this manually by changing the step size you are using, i.e.

x = 0:0.1:100;
L = 0:0.1:100;
t = 0:0.3:300;

Another way to define vectors that explicitly defines the number of elements is `linspace'. You might use:

x = linspace(0, 100, 1001);
L = linspace(0, 100, 1001);
t = linspace(0, 300, 1001);

This will give you 1001 points for each vector in the ranges specified.

like image 171
nicktruesdale Avatar answered May 09 '26 15:05

nicktruesdale



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!