what's wrong with this code. why it show error can anyone tell?

1 visualización (últimos 30 días)
Ayesha Altaf
Ayesha Altaf el 10 de En. de 2021
Respondida: Alan Stevens el 10 de En. de 2021
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.

Respuestas (1)

Alan Stevens
Alan Stevens el 10 de En. de 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

Categorías

Más información sobre Particle & Nuclear Physics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by