how to replace variable by another variable

Hn=-2*P/(Mu*exp(n^2*pi^2*T/Mu))
I want to replace T by t and want to do calculation

2 Comments

Can you elaborate the query,on whats the result you are getting when you replace "T" with "t" in the equation itself i.e
Hn=-2*P/(Mu*exp(n^2*pi^2*t/Mu))?
actually I have to replace T by t/L and again i have to give different value to t for calculation. and some for loop is also involve in the equation for n

Sign in to comment.

Answers (3)

if you are using the symbolic toolbox then subs()

6 Comments

if i want to give some numeric value to new variable then how to give
syms L Mu n P T t
Pi = sym(pi);
Hn=-2*P/(Mu*exp(n^2*Pi^2*T/Mu))
Hn = 
Hn_new = subs(Hn, T, t/L)
Hn_new = 
subs(Hn_new, t, (1:5).')
ans = 
it is a great help for me.
can you please tell me if I want to give value of t as 5, 10, 15, 20,25,.......,1000 then how to give here in the code. thanks in advance.

Sign in to comment.

when I'm using the following code to evaluate z value . I'm getting the Q value and all the value after Q is zero. I m not getting where I'm wrong.
clc;
clear all;
close all;
l=10000;
x=0:100:l;
t=[0;1;5;10;15;20;25];
H=30;
Mu=2.8e-1;
D=31;
k=0.01132;
k1=l/H;
for n=1:100
a=2*H;
b=(1-(-1)^n*exp(-k*l))/((n*pi+(k^2*l^2)/(n*pi)));
c=1/(n*pi);
Cn(n)=a*(b-c);
end
s=0;
for n=1:100
d= sin(n*pi*x/l);
q= exp((-n^2*pi^2*t)/(Mu^2*l));
aa=Cn(n).*d.*q;
s=s+aa;
end
syms X T
for n=1:100
H0=@(X,T)Cn(n).*sin(n*pi*X).*exp(-n^2*pi^2*T/Mu)+H*X/(D-H)+H/(D-H);
y=diff(H0*diff(H0,X),X);
Q=int(y*sin(n*pi*X),X,0,1);
P=int(Q*exp(n^2*pi^2*T/Mu),T,0,T);
Hn=-2*P/(Mu*exp(n^2*pi^2*T/Mu));
H1=Hn.*sin(n*pi*X);
for i=1:size(t,1)
for j=1:length(x)
H=(subs(H1,{X,T},{x(j)/l,t(i,1)/(Mu*l)}));
ZZ(j,1)=double(H);
end
XX(i,1)=sum(ZZ);
clear ZZ
end
s1=((D-H)^2).*XX/l;
end
j=(H*x)/l;
z=s-j-s1
plot(x,z)

4 Comments

I think you are getting some underflow, exp(-number) terms that evaluate in floating point to zero even though mathematically they are not zero.
suppose I have a variable z and it has 100 values for each time variable t (suppose t= 0,1,5, 10,15). suppose one variable cell V{} contains 100 value for different time, then how to minus z and V{} values
I want to multiply r and f value in the following code. how to do it.
clc;
clear all;
close all;
L=600;
T=365;
delt=0.025;
k=8.64;
aa=delt*k*(1+delt);
epc=0.3;
H=50;
mu=epc/(k*delt*H);
w1=86400*1*10^-8;
w2=8*86400*10^-8;
dx=1;
dt=1;
d=(mu*dt)/(dx^2);
N=L/dx +1;
M=T/dt +1;
for i=1:N
x(i)=0+(i-1)*dx;
end
for n=1:M
t(n)=0+(n-1)*dt;
end
for n=1:M
for i=1:N
if x(i)>=250 && x(i)<=350
r(i)=w2;
else
r(i)=w1;
end
end
if t(n)<=182.5
f(n)=sin(2*pi*t(n)/365).^2;
else
f(n)=0;
end
end

Sign in to comment.

I'm writing the following but it is giving me zero and showing matrix dimension is not agree
clc;
clear all;
close all;
L=600;
T=365;
delt=0.025;
k=8.64;
aa=delt*k*(1+delt);
epc=0.3;
H=50;
mu=epc/(k*delt*H);
w1=86400*1*10^-8;
w2=8*86400*10^-8;
dx=1;
dt=1;
d=(mu*dt)/(dx^2);
N=L/dx +1;
M=T/dt +1;
for i=1:N
x(i)=0+(i-1)*dx;
end
for n=1:M
t(n)=0+(n-1)*dt;
end
for n=1:M
for i=1:N
if x(i)>=250 && x(i)<=350
r(i)=w2;
else
r(i)=w1;
end
end
if t(n)<=182.5
f(n)=sin(2*pi*t(n)/365).^2;
else
f(n)=0;
end
f2=r.*f
end
f2 = 1×601
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Arrays have incompatible sizes for this operation.

5 Comments

for n=1:M
for i=1:N
if x(i)>=250 && x(i)<=350
r(i)=w2;
else
r(i)=w1;
end
end
r is a vector of length N after that for i loop.
if t(n)<=182.5
f(n)=sin(2*pi*t(n)/365).^2;
else
f(n)=0;
end
f is a vector of length n after that if test -- it is being expanded as do more interations of for n
f2=r.*f
r is 1 x N vector. f is a 1 x n vector. They can only be .* together if the changing variable n == N or n == 1 (in which case 1 x N .* 1 x 1 would be scalar expansion.)
I want to plot between x and -(z(n+1,i)).^0.5. how to get it?
clc;
clear all;
close all;
L=600;
T=365;
delt=0.025;
k=8.64;
aa=delt*k*(1+delt);
epc=0.3;
H=50;
mu=(k*delt*H)/epc;
w1=1*86400*10^-8;
w2=2*86400*10^-8;
dx=1;
dt=1;
d=(mu*dt)/(dx.^2);
N=L/dx +1;
M=T/dt +1;
for i=1:N
x(i)=0+(i-1)*dx;
end
for n=1:M
t(n)=0+(n-1)*dt;
end
for n=1:M
for i=1:N
if x(i)>=250 && x(i)<=350
r(i)=w2;
else
r(i)=w1;
end
if t(n)<=182.5
f(n)=sin(2*pi*t(n)/365).^2;
else
f(n)=0;
end
Q(n,i)=(2*r(i)*f(n)*mu)/aa;
end
end
for n=1:M
z(n,1)=0;
z(n,N)=0;
end
for i=1:N
z(1,i)=0;
end
for n=1:M-1
for i=2:N-1
z(n+1,i)=z(n,i)+d*(z(n,i+1)-2*z(n,i)+z(n,i-1))+Q(n,i)*dt;
end
end
I want to plot between x and -(z(n+1,i)).^0.5
Do you mean that you have an independent variable 1:N on the x axis, and you want to treat the variable x and that particular expression as dependent variables to be drawn and you want to fill the area between the two lines?
Or is your x variable to be treated as the x axis and you want to draw -(z(n+1,i)).^0.5 even though that appears to be independent of x?
tell me for both the conditons as well

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Asked:

on 8 Feb 2023

Commented:

on 29 Apr 2023

Community Treasure Hunt

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

Start Hunting!