I want to solve it with the unknown

1 vue (au cours des 30 derniers jours)
주선 문
주선 문 le 25 Août 2022
Modifié(e) : Dyuman Joshi le 25 Août 2022
clc,clear;close all;
syms r Nddotmax;
f = @(t,y,s,r,Nddotmax) (r*((1-y)/Nddotmax)+s-0.0012*0.02*y); %y=Nddotexi,vmed=0.02,fdot=3*10^(-18),r=0.0012,s=Nsurv
a = 0; %input('initial ponit, a: ');
b = 100; %input('end point, b: ');
n = 10; %input('intervals, n: ');
alpha = 0; %input('initial condition, alpha: ');
h = (b-a)/n;
t=[a zeros(1,n+1)];
y=[alpha zeros(1,n+1)];
s=[0 zeros(1,n+1)];
for i = 1:n+1
t(i+1)=t(i)+h;
yprime=y(i)+h*f(t(i),y(i),s(i)); %slope
y(i+1)=y(i)+h*f(t(i+1),yprime,s(i+1));
fprintf('%.4f %.4f\n', t(i), y(i));
figure(1)
plot(t,y,'r-o');
xlabel('t values'); ylabel('y values');
grid on; hold on;
legend('y')
end
But there is a problem that input is not enough(Insufficient input arguments.)
then how can i fix it?

Réponse acceptée

Dyuman Joshi
Dyuman Joshi le 25 Août 2022
Modifié(e) : Dyuman Joshi le 25 Août 2022
You have defined your function handle as -
f = @(t,y,s,r,Nddotmax) (r*((1-y)/Nddotmax)+s-0.0012*0.02*y);
Which means it requires 5 inputs to give you an output. Though 't' isn't mentioned in the expression, so either remove it or check the expression again.
But you are only calling it with 3 inputs, that is why it is giving the error
yprime=y(i)+h*f(t(i),y(i),s(i)); %slope
y(i+1)=y(i)+h*f(t(i+1),yprime,s(i+1))
To fix the problem, call your function handle with 5 input.
Also, defining syms variable is redundant as you are using a function handle.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by