Ask your own question, for FREE!
Computer Science 15 Online
OpenStudy (anonymous):

Can anyone please help me to write this matlab m-file? Here is the pseudocode : http://oi53.tinypic.com/u1pvc.jpg

OpenStudy (anonymous):

function y=lgrng(x,y,i,j) sum = 0 ; while i = 0,n product = yi; while j = 0,n if a ~= b then product = product * ( x - xj ) / (xi - xj) end end sum = sum + product; end print sum; end

OpenStudy (anonymous):

this is what i tried to write,too bad it didn t work.

OpenStudy (anonymous):

Of course not, you tried to paste the algorithm into a .m without regard to Matlab syntax and the picture algorithm is badly written. I can't tell if it means a do while or for loop or what types of inputs you are using (vectors, constants, etc).

OpenStudy (anonymous):

I'll get you started off, but I have no idea about you are attempting to accomplish, what test cases you have, what the inputs are or what information you have about this. You have two inputs with the same name. I recommend including better info in the future... function sum = test(x, y, n) % assuming y is a vector % assuming x is a vector sum = 0; for i = 1 : n product = y(i); for j = 1 : n if i ~= j product = product .* (x - x(j)) ./ (x(i) - x(j)) end end sum = sum + product; end return

OpenStudy (anonymous):

It seems from the picture that there is another parameter 'X'. you should name it differently as JD pointed out. otherwise this line 'product = product .* (x - x(j)) ./ (x(i) - x(j))' won't work. Try change x into x1 and include it into the function at the first line. Good luck

OpenStudy (anonymous):

Assuming x is a vector, you are subtracting a scalar from a vector (which is fine), dividing a vector by a scalar (which is fine) and multiplying each vector element by a scalar (which is fine).

OpenStudy (anonymous):

yeah, but can't figure out what this function is trying to do. This is a real problem.

OpenStudy (anonymous):

hi guys,sorry for the late reply,thank you very much for your help. and here is the whole question: http://oi55.tinypic.com/20r4ryp.jpg

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!