3
votes

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)')
3
You have 2 vectors, one with 1001 elements, and the other with 334 elements. How exactly do you propose element-wise division of these 2 should work?Praetorian

3 Answers

4
votes

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.

0
votes

Yes, that is because L is 1x334 and x is 1x1001. To divide element by element they need to have the same number of elements.

0
votes

x stores 0 to 100 at increments of 0.1
L stores 0 to 100 at increments of 0.3
So number of elements in L is less than the number of elements in x if x has the elements x = {x1 x2 x3} and L = {L1 L2 L3}, then x./L is supposed to give
ans = {x1/L1 x2/L2 x3/L3}. If the number of elements in numerator and denominator arrays are not the same then Matlab will give an error