MATLAB Answers

In an assignment A(I) = B, the number of elements in B and I must be the same

36 views (last 30 days)
Lutfi Adam
Lutfi Adam on 24 Jan 2021
Edited: Walter Roberson on 24 Jan 2021
Hi, I need help.
What should i do for fix this error
function dydt = fix_reaksi_tumor_glioma(t,y)
dydt = zeros(size(y));
% Parameter model pertumbuhan glioma (1 g/ml = 10^3 mg/ml)
aT = 1.575; % ml^2 g^-2 day^-1
KT = 2; % g/ml
dTI = 0.072; % day^-1
aTI = 3*10^-4; % day^-1
dT = 1*10^-4; % day^-1
dI = 0.01; % day^-1
as = 0.7; % day^-1
v = 0.7; % day^-1
dTo = 1; % day^-1
ao = 20; % day^-1
omin = 8.00*10^-4; % g/ml
o0 = 1.6*10^-3; % g/ml
do1 = 0.01; % day^-1
do2 = 0.00625; % day^-1
dTT = 0.72; % day^-1
f_glukosa = omin*sin(6*pi*t); %Asupan glukosa
T = y(1); % pertumbuhan sel glioma (Tumor)
B = y(2); % konsetrasi glukosa dalam otak (obrain)
I = y(3); % aktivitas sistem kekebalan tubuh (imune)
S = y(4); % konsentrasi glukosa dalam serum (oserum)
dydt(1)= aT*B*T*(1-T/KT) - dT*T - dTI*T*I;
dydt(2)= ao*(S-B) - dTo*T*B - (do1+as*(v+I))*B;
dydt(3)= as*(v+I)*B + aTI*T*I - dI*I - dTT*T*I;
dydt(4)= ao*(B-S) + f_glukosa - do2*S;
dydt=[dydt(1); dydt(2); dydt(3); dydt(4)];
I get error
Error in fix_reaksi_tumor_glioma (line 33)
dydt(4)= ao*(B-S) + f_glukosa - do2*S;
K>> dydt(4)= ao*(B-S) + f_glukosa - do2*S;
In an assignment A(I) = B, the number of elements in B and I
must be the same.

Answers (1)

VBBV on 24 Jan 2021
What is size of time t in the
f_glukosa = omin*sin(6*pi*t)
Walter Roberson
Walter Roberson on 24 Jan 2021
t(:) takes whatever values are in t and makes a column vector out of them. The .' after that transposes the column vector into a row vector. t(:).' is a short way of writing reshape(t, 1,[])
The reason why I coded that is that if t is not a scalar then it takes too much explanation and self discipline to force it to be either a row vector or a column vector specifically. If I had coded assuming it was a column vector you might have replied that it was a row vector or 2d array and I would have had to adjust the code to handle whatever you turned out to be passing in. It saved rounds of back and forth with you and future readers for me to code it the first time in a way that did not depend on what exactly the input shape is.
I already demonstrated above that your original function works without change with ode45. The only change I made was to add a final "end" to your code, which is required if you use the function in a script the way I did here, but would not be necessary if you had stored the code in its own fix_reaksi_tumor_glioma.m file.
The changes I made later with the t(:) and so on are only needed if you are invoking the function in your own custom code, such as if it had turned out that you are building your own RK45 or Euler integration function.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!