i have an error about the general solution. it says that it's not found in the code

1 次查看(过去 30 天)
%A zircon sample contains 5000 atoms of the radioactive element 235U.
%Given that 235U has a half‐ life of 650 million years, how long would it take to decay to 120 atoms?
%Setup the variables A(t), k that will be used in the program. Find also the derivative of A(t) and set as dA
syms k t A(t) dA x
dA = diff(A,t)
%Initial Conditions
cond1= A(0)==5000
cond2= A(650)==2500
%Set the differential equation model as eqn1;
eqn1 = dA==k*A
A(t) = dsolve(eqn1)
%Find k1 and k2, by solving the initial value problem eqn1 using cond1 and cond2, respectively.
k1 = dsolve(eqn1,cond1)
k2 = dsolve(eqn1,cond2)
%Solve for k by equating k1 and k2 at t=0. Save results as k.
h1 = subs (k1,sym("t"),0)
h2 = subs (k2,sym("t"),0)
k = solve(h1==h2,k)
%Solve the eqn1 using the acquired value of k and using Initial value cond1.
A0 = 5000==(subs(subs(dsolve(eqn1),sym("k"),k),t,0))
Ao = double(lhs(A0))
%Solve the equation when A(t) = Acondition. Save Answer as tfinal (This is in Million Years)
tsoln = 125==subs((subs(dsolve(eqn1),sym("k"),k)),sym("C1"),Ao)
isolate(tsoln,t)
tfinal = solve(tsoln,t)
A(t) = symfun(lhs(subs(subs(dsolve(eqn1),sym("k"),k),sym("C1"),A0)),t)
Asoln = symfun(subs((A(t)),sym("t"),sym("x")),x)
%Express your answer in years
tM = double(tfinal*10^6);
% Plot the equation: Use the Title=Radioactive Decay, XValue=Period(Million of Years), YValue=Atoms of 235U
Title = "Radioactive Decay"
XValue = "Period(Million of Years)"
YValue = "Atoms of 235U"
hold on;
title(Title)
xlabel(XValue)
ylabel(YValue)
%Use the domain (0, tfinal+5) with 0.2 gaps from each point
x=0:0.2:tfinal+500;
y=Asoln(x);
plot(x,y)
hold off;

回答(1 个)

Torsten
Torsten 2022-6-11
编辑:Torsten 2022-6-11
syms A(t) k
eqn = diff(A,t) == k*A;
cond = A(0) == 5000;
S = dsolve(eqn,cond);
k_num = solve(subs(S,t,650)==2500,k);
S_num = subs(S,k,k_num);
S_num = matlabFunction(S_num);
t = 0:1:1300;
plot(t,S_num(t))

类别

Help CenterFile Exchange 中查找有关 Particle & Nuclear Physics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by