Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Dear Matlab, Last week I showed my MatLab code to my major professor and when he

ID: 2997383 • Letter: D

Question

Dear Matlab, Last week I showed my MatLab code to my major professor and when he saw the following loop he went crazy and went into a 15 min long lecture about how I am not using the full capabilities of MatLab and that I'm creating ineffective and computationally heavy code, etc. Anyhow, what I got out of lecture is that there is a better way of writing this loop (even though it works as it is). Can you help me figure out what that is? I am tying to find: S = sigma^1000 1 anbn where alphan = 1: 1000and bn = 1000 - an. I did this with the following loop: >> a = [1 : 1000]; >> s=0; >> for n = 1 : 1000 b(n) = 1000-a(n); s = s + a(n)*b(n); end

Explanation / Answer

This code gives the desired value of S

a=[1:1000];
b=[1000:-1:1];
c = transpose(b);
S = a*c

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote