what's wrong with this code. why it show error can anyone tell?
Show older comments
function matlab
clc;clear;
%Radioactive decay
y0=[5*10^26;0];
soln = ode23(@f1,[0 8],y0)
t = linspace(0,8,24);
y(:,1)=deval(soln,t,1); %Strontium
y(:,2)=deval(soln,t,2); % Yttrium
figure
plot(t,y(:,1),'-o',t,y(:,2),'--');
hold on;grid on;
legend('Strontium','Yttrium')
end
function dxdt = f1(x,t)
r1 = 0.256;
r2 = 0.127;
dxdt(1) = -r1 * x;
dxdt(2) = -r2 * x;
dxdt =dxdt';
end
function matlab
↑
Error: Function definition not supported in this context. Create functions in code file.
Answers (1)
Alan Stevens
on 10 Jan 2021
You probably want something like this (don't enclose it with the statement 'function matlab' - that won't work).
Remember to include the build-up of Ytterbium from Strontium, or ytterbium's curve will stay at zero!).
%Radioactive decay
y0=[5*10^26;0];
soln = ode23(@f1,[0 8],y0);
t = linspace(0,8,24);
y(:,1)=deval(soln,t,1); %Strontium
y(:,2)=deval(soln,t,2); % Yttrium
figure
plot(t,y(:,1),'-o',t,y(:,2),'--');
grid on
legend('Strontium','Ytterbium')
function dydt = f1(~,y)
r1 = 0.256;
r2 = 0.127;
dydt(1) = -r1 * y(1);
dydt(2) = r1*y(1) -r2 * y(2);
dydt =dydt';
end
Categories
Find more on Particle & Nuclear Physics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!