# why is my matlab code doesn't give the right answer

1 vue (au cours des 30 derniers jours)
Khang Nguyen le 22 Nov 2020
Commenté : Khang Nguyen le 22 Nov 2020
I want to do remain sum form 0 to 3 or sqrt(x+1) from the left with 10 to 100 sub interval,
the graph have to go from small to big but somehow my code go from big to small. please let me know what i did wrong, all the equation are correct
I use the exact way on python and it gave me the graph the graph that I want
hold off
sumvec1 = []
for n = 10:100
sum = 0;
width = ((3 - 0)/n) ;
for c = 0:n
base1 = (width) * c- width ;
height = sqrt((base1 +1));
sum = sum + (width * height);
end
sumvec1(n-9) = sum;
end
figure;
i = 1:length(sumvec1)
scatter(i,sumvec1)
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (1)

Sibi le 22 Nov 2020
Modifié(e) : Sibi le 22 Nov 2020
Try this (edited)
hold off
sumvec1 = [];sum = 0;
for n = 10:100
width = ((3 - 0)/n) ;
for c = 0:n
base1 = (width) * c- width ;
height = sqrt((base1 +1));
sum = sum + (width * height);
end
sumvec1 =[ sumvec1 sum];
end
figure;
i = 1:length(sumvec1);
scatter(i,sumvec1)
##### 4 commentairesAfficher 2 commentaires plus anciensMasquer 2 commentaires plus anciens
Sibi le 22 Nov 2020
i have edited the code , check now.
Khang Nguyen le 22 Nov 2020
I am hoping for a graph that looks like a logthirthmic graph. Since the area will get bigget with more interval. It will approach a certain area. The area it's approaching in the intergral from 0 to 3 of the equation. I hole this make sense.
Thank you for follow up and help me,
I appreciate it

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Directed Graphs 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