Array indices must be positive integers or logical values.

Error in TASKA (line 22)
A(t)=(A0-B0/YB)./(1-(B0/(YB*A0))*exp(-((YB*A0/B0)-1)*K*B0.*t));

5 Kommentare

What is the value of t? The only thing you are indexing into is A. The error appears to tell you that t is not a positive integer or logical value.
You cannot index with 0 (indexing for matlab starts at 1)
my initial value is 0 and final value is 12 hours i need to find the value inbetwwen this time
Cannot help further unless you provide more information (all variables with values and context)

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Image Analyst
Image Analyst am 6 Mär. 2022
A thorough discussion is in the FAQ:
In the meantime, try getting rid of (t) on the left hand side.
A = (A0-B0/YB) ./ (1-(B0/(YB*A0)) .* exp(-((YB*A0/B0)-1)*K*B0 .* t));
clc
clear all
YB=1;
YP=0.15;
A0=1;
B0=3;
P0=0;
K= 5E-5;
ti=0;
tf=12;
F=@(t,y)[-K*y(1)*y(2);-YB*K*y(1)*y(2);YP*K*y(1)*y(2)];
% create function of ODE
% f = [da/dt;db/dt,dp/dt]
[t,y]= ode89(F,[ti tf],[A0;B0;P0]);
%ODE89
A(t)=(A0-B0/YB)/(1-(B0/(YB*A0))*exp(-((YB*A0/B0)-1)*K*B0*tf));
% Analytical solution
plot(tf,y(:,1),'-0',tf,A_t','-*')
title('Solution of ODE with ODE89 and comparison with Analytical value');
xlabel('Time t');
ylabel('solution A(ODE89)& A(t) Analytical Value');
xlabel('Time t');
ylabel('solution A (ODE89) & A(t) Analytical value');
xlabel('Time t');
ylabel('Solution A(ODE89) & A(t) Analytical ');
legend('A(ODE89)','A(t) Analytical')
disp('time A(ODE89) A(t) Analytical ')
disp([tf y(:,1) A_t])

3 Kommentare

Image Analyst
Image Analyst am 6 Mär. 2022
Bearbeitet: Image Analyst am 6 Mär. 2022
You posted this as the "Answer".
So, did this "Answer" of your fix it? Otherwise take another look at my answer.
I tried using removing t in A but it shows
Error using plot
Invalid color or line style.
Error in TASKA (line 26)
plot(tf,y(:,1),'-0',tf,A,'-*')
plot(rand(1,5), '-o')
plot(rand(1,5), '-O')
plot(rand(1,5), '-0')
Error using plot
Invalid color or line style.
which is to say that your '-0' is dash-zero and that is not a recognized line style or color. Using dash-oh or dash-capital-oh is fine.

Melden Sie sich an, um zu kommentieren.

Produkte

Version

R2021b

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by