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

조회 수: 1 (최근 30일)
Ayesha Altaf
Ayesha Altaf 2021년 1월 10일
답변: Alan Stevens 2021년 1월 10일
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.

답변 (1개)

Alan Stevens
Alan Stevens 2021년 1월 10일
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

카테고리

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