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

To be programmed in MatLab Dear Matlab, Last week I showed my MatLab code to my

ID: 2074136 • Letter: T

Question

To be programmed in MatLab

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 the 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 trying to find: S-voo an bn where an 1: 1000 and bn 1000 an I did this with the following loop: >> a = [1:10001; >> s=0; >> for n = 1:1000 b (n) = 1000-a (n); s = s + a (n) *b (n); end Thanks Thoroughly rebuked

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