function LASTONE clear; dt = .1; tspan = [0:dt:20]; IN = zeros(1,length(tspan));
ID: 3860257 • Letter: F
Question
function LASTONE
clear;
dt = .1;
tspan = [0:dt:20];
IN = zeros(1,length(tspan));
IN(8 <= tspan < 8.1) = 10;
KOB = 0;
KLB = 0.5;
KBO = 0.9;
KBL = 0.8;
KLO = 0.3;
y0 = [0 0];
[t,y] = ode45(@(t,y)hwfun(t,y,IN,KOB,KLB,KBO,KBL,KLO),tspan,y0);
figure;
plot(t,y(1,:),'r',t,y(2,:),'b-');
end
function dy = hwfun(~,y,IN,KOB,KLB,KBO,KBL,KLO)
dy = zeros(2,1);
dy(1) = (KOB + (KLB .* y(1,:)) - (KBO + KBL) .* y(2,:) + IN);
dy(2) = ((KBL .* y(2,:)) - (KLO + KLB) .* y(1,:));
end
Here is my code but I keep getting this error so idk what im doing wrong. Any help would be appreciated
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in LASTONE>hwfun (line 30)
dy(1) = (KOB + (KLB .* y(1,:)) - (KBO + KBL) .* y(2,:) + IN);
Error in LASTONE>@(t,y)hwfun(t,y,IN,KOB,KLB,KBO,KBL,KLO) (line 17)
[t,y] = ode45(@(t,y)hwfun(t,y,IN,KOB,KLB,KBO,KBL,KLO),tspan,y0);
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in LASTONE (line 17)
[t,y] = ode45(@(t,y)hwfun(t,y,IN,KOB,KLB,KBO,KBL,KLO),tspan,y0);
Explanation / Answer
function LASTONE
clear;
dt = .1;
tspan = [0:dt:20];
IN = zeros(1,length(tspan));
IN(8 <= tspan < 8.1) = 10;
KOB = 0;
KLB = 0.5;
KBO = 0.9;
KBL = 0.8;
KLO = 0.3;
y0 = [0 0];
[t,y] = ode45(@(t,y)hwfun(t,y,IN,KOB,KLB,KBO,KBL,KLO),tspan,y0);
figure;
plot(t,y(1,:),'r',t,y(2,:),'b-');
end
function dy = hwfun(~,y,IN,KOB,KLB,KBO,KBL,KLO)
dy = zeros(2,1);
dy(1) = (KOB + (KLB .* y(1,:)) - (KBO + KBL) .* y(2,:) + IN);
dy(2) = ((KBL .* y(2,:)) - (KLO + KLB) .* y(1,:));
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.