There is an apparent error in line 4, and this code only ran once
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everyone, I am currently trying to figure out what is wrong with my code:
t = [36, 65, 100, 160];
c = [0.145, 0.120, 0.100, 0.080];
t2 = (20:10:160);
c2 = b*exp(t2*m);
plot(t, c)
plot(t, c, '*g', t2, c2, '-g');
P = polyfit(t, log(c), 1);
m = P(1);
b = exp(P(2));
TE = sprintf('C = %0.2fe^{%0.3ft}',b, m);
text(43, 0.085, TE);
I wrote 2 codes that are similar to the one above, but it said there is an error in line 4 (which matlab detected the same line for both codes) after I cleared everything in the command window. Is there an error that I am not aware of? Thanks
0 commentaires
Réponses (3)
Rik
le 13 Oct 2021
t = [36, 65, 100, 160];
c = [0.145, 0.120, 0.100, 0.080];
t2 = (20:10:160);
c2 = b*exp(t2*m);
As you can see, you didn't define the variable b.
Cris LaPierre
le 13 Oct 2021
The issue I see is that you are using b in line 4 to calculate c2, but do not define b until line 9. Perhaps you just need to reorganize your code?
t = [36, 65, 100, 160];
c = [0.145, 0.120, 0.100, 0.080];
t2 = (20:10:160);
P = polyfit(t, log(c), 1);
m = P(1);
b = exp(P(2));
c2 = b*exp(t2*m);
plot(t, c, '*g', t2, c2, '-g');
TE = sprintf('C = %0.2fe^{%0.3ft}',b, m);
text(43, 0.085, TE);
1 commentaire
Mathieu NOE
le 13 Oct 2021
hello
simply b and m are not yet defined when you do in line 4 :
c2 = b*exp(t2*m);
the code should be organized like this :
t = [36, 65, 100, 160];
c = [0.145, 0.120, 0.100, 0.080];
P = polyfit(t, log(c), 1);
m = P(1);
b = exp(P(2));
t2 = (20:10:160);
c2 = b*exp(t2*m);
plot(t, c, 'dr', t2, c2, '-b');
TE = sprintf('C = %0.2fe^{%0.3ft}',b, m);
text(t2(4), c2(4) + 0.004, TE);
0 commentaires
Voir également
Catégories
En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!