In this program i want to assign C(0)=c0 and i need to plot values of C(t) from t=0 to 6. Also i need to plot the values of C(t) for v=1,5,-1,-5. I got an error as Attempted to access c(0)index must be a positive integer or logical. anyone help me?

1 vue (au cours des 30 derniers jours)
clear all;
k=10e6;
cmin=10e-9;
cmax=10e-6;
c0=100e-9;
v=1;
for t=1:6
C(t)=c0-sqrt(1+(2*c0^2*k*(1/cmin-1/cmax)*v*t));
end
plot(t,C,'r');

Réponse acceptée

Image Analyst
Image Analyst le 21 Août 2014
Modifié(e) : Image Analyst le 21 Août 2014
Your code does not generate that error message, but in general, indexes in MATLAB start at 1 not 0 like in C and some other languages.
clc; % Clear the command window.
close all; % Close all figures.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
fontSize = 22;
k=10e6;
cmin=10e-9;
cmax=10e-6;
c(1)=100e-9;
v=1;
for t=1:6
c(t+1) = c(1)-sqrt(1+(2*c(1)^2*k*(1/cmin-1/cmax)*v*t));
end
t = 0 : 6;
plot(t, c , 'rd-', 'LineWidth', 2);
grid on;
xlabel('t', 'FontSize', fontSize);
ylabel('c', 'FontSize', fontSize);
  2 commentaires
vetri veeran
vetri veeran le 21 Août 2014
Thank you for the answer. In the same graph, I need to plot the values of C(t) for different values of v=1,5, -1,-5.how this can be done to the above code.
Image Analyst
Image Analyst le 21 Août 2014
You can either make a family of curves, or turn c into a 2D image.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by