1 view (last 30 days)

clear all

clc

y = linspace(-5,5,100);

T0 = 303.15;

A = 0.5;

k = 7.2;

alpha = 2.96*10^-6;

P = 200;

v = 1;

x1 = 0;

x2 = -0.002;

x3 = -0.0035;

%r1 = ((x1)^2+y^2)^0.5;

%r2 = ((x2)^2+y^2)^0.5;

%r3 = ((x3)^2+y^2)^0.5;

T1 = (T0)+((A * P /(2*pi*k*(((x1)^2+y^2)^0.5)))*exp((-v)*((((x1)^2+y^2)^0.5)+(x1)))/(2*alpha));

T2 = (T0)+((A * P /(2*pi*k*(((x2)^2+y^2)^0.5) ))*exp((-v)*((((x2)^2+y^2)^0.5)+(x2)))/(2*alpha));

T3 = (T0)+((A * P /(2*pi*k*(((x3)^2+y^2)^0.5)))*exp((-v)*((((x3)^2+y^2)^0.5)+(x3)))/(2*alpha));

figure

plot(y,T1,'blue')

hold on

plot(y,T2,'red')

hold on

plot(y,T3,'orange')

axis([-0.0005 0.0005 0 2000])

legend('y(m)','Temperature(K)')

John D'Errico
on 25 Jan 2020

Edited: John D'Errico
on 25 Jan 2020

When you say only that something does not run, then tell people what was the error message. Show the COMPLETE error message. Thus everything in red. In this case, the answer is obvious, and the first mistake most new users of MATLAB make, when they fail to have read the getting started tutorials.

y is a vector. What happens when you try this in matlab?

y = 1:5;

y^2

Error using ^ (line 51)

Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix

powers, use '.^'.

What did it tell me to do? It told me that it cannot raise y to a power, and that I should probably consider using .^ instead. I want to compute the element-wise powers of each element in the vector. So I need to use the .^ operator.

y.^2

ans =

1 4 9 16 25

Likewise, when I wish to multiply or divide each element of a vector with another of the same size, I need to use the .* and ./ operators. If you had read the manual, it would have discussed this.

So now look at the line:

T1 = (T0)+((A * P /(2*pi*k*(((x1)^2+y^2)^0.5)))*exp((-v)*((((x1)^2+y^2)^0.5)+(x1)))/(2*alpha));

Did you use the .^ and .* and ./ operators in there as needed?

You can get away with operations like 2*y, as one of the operands is a scalar. MATLAB recognizes that a scalar multiply should be extended to every element of the other operand. Be careful however, as this does not extend to the ^ and / operators.

Finally, there is no problem with addition and subtraction of vectors and arrays. As long as they are of conforming size and shape, MATLAB needs to do nothing special. So there is no such thing as a .+ operator in MATLAB.

suleiman abdullahi
on 25 Jan 2020

you should use the elementwise operation e.g [.* and .^]. like this below

T1 = (T0)+((A .* P ./(2.*pi.*k.*(((x1).^2 + y.^2).^0.5))).*exp((-v)*((((x1).^2 + y.^2).^0.5)+(x1)))./(2.*alpha));

Opportunities for recent engineering grads.

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

Start Hunting!
## 0 Comments

Sign in to comment.