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); endExplanation / Answer
This code gives the desired value of S
a=[1:1000];
b=[1000:-1:1];
c = transpose(b);
S = a*c
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.