how can I write a function of another function of two variables

How can I wtite
where are constant.
in such a way I can evaluate vectors in it, For example ,where
Lt=linespace(0,1,10) and Lt=linespace(0,10,10)

답변 (1개)

Create the ρ function and then call it in the μ function —
rho = @(t,z) something;
mu = @(t,z) c .* log(rho(t,z)*b ./ (1 - rho(t,z)*b)) + rho(t,z)*b./(1-rho(t,z)*b);
Example —
b = rand
b = 0.4246
c = rand
c = 0.0166
rho = @(t,z) t./z;
mu = @(t,z) c .* log(rho(t,z)*b ./ (1 - rho(t,z)*b)) + rho(t,z)*b./(1-rho(t,z)*b);
Li = linspace(0, 1, 10);
Lz = linspace(0, 10, 10);
Mu = mu(Li, Lz)
Mu = 1x10
NaN -0.0072 -0.0072 -0.0072 -0.0072 -0.0072 -0.0072 -0.0072 -0.0072 -0.0072
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
.

댓글 수: 8

Thank you for your fast response.
but I am actually don't have a specific expression for , but I am using a numerical method and the value of it will be taken from the previous step.
My pleasure!
Can you be more specific about what actually is? My approach should work regardless. It is all just a matter of coding .
Maryam Albuhayr
Maryam Albuhayr 2024년 5월 22일
편집: Maryam Albuhayr 2024년 5월 22일
yes,
I am actually applying FDM as follows,
and I have tried several ways to do it correctly but still it didn't work.
rho=zeros(N,M);
% BC
rho(1,:)=7000; %mol/m^3
rho(N,:)=0;
% % IC
%
rho(:,1)=7000+(7000/D)*z;
for i=2:N-1
for n=1:M-1
mu(rho(i,n))= 3 .* log(rho(i,n)*4 ./ (1 - rho(i,n)*4)) + rho(i,n)*4./(1-rho(i,n)*4);
rho(i,n+1)=Lambda*rho(i+1,n)+(1-2*Lambda)*rho(i,n)+Lambda*rho(i-1,n)+ mu(rho(i,n));
end
end
Didn't you forget time stepsize dt and spatial stepsize dz somewhere in the update for rho ?
rho=zeros(N,M);
% BC
rho(1,:)=7000; %mol/m^3
rho(N,:)=0;
% % IC
%
rho(:,1)=7000+(7000/D)*z;
for n=1:M-1
for i=2:N-1
mu = 3*log(rho(i,n)*4/(1 - rho(i,n)*4)) + rho(i,n)*4/(1-rho(i,n)*4);
rho(i,n+1)=Lambda*rho(i+1,n)+(1-2*Lambda)*rho(i,n)+Lambda*rho(i-1,n) + mu;
end
end
there are many details that I did not lit here
of course I defineded them, here is what I wrote before
D=8;
T=1;
dz=0.2;
dt=0.02;
%-----------------------------------------------------
Lambda=dt/(dz^2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N=D/dz+1; % space nodes
M=T/dt+1; % time nodes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
z=zeros(N,1);
t=zeros(M,1);
for i=1:N
z(i)=(i-1)*dz;
end
for n=1:M
t(n)=(n-1)*dt;
end
It's very unusual to give dt/dz^2 the name Lambda. Lambda is thermal conductivity in general.
So your code works now ? At least it should no longer give syntax errors.
Unfortunately, not yet

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2024년 5월 22일

댓글:

2024년 5월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by