Array indices must be positive integers or logical values.

2 views (last 30 days)
Error in TASKA (line 22)
A(t)=(A0-B0/YB)./(1-(B0/(YB*A0))*exp(-((YB*A0/B0)-1)*K*B0.*t));
  5 Comments
Navaneetha Krishnan Murugadoss
my initial value is 0 and final value is 12 hours i need to find the value inbetwwen this time
David Hill
David Hill on 6 Mar 2022
Cannot help further unless you provide more information (all variables with values and context)

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 6 Mar 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));

Navaneetha Krishnan Murugadoss
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 Comments
Navaneetha Krishnan Murugadoss
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,'-*')
Walter Roberson
Walter Roberson on 6 Mar 2022
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.

Sign in to comment.

Categories

Find more on Functions in Help Center and File Exchange

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!