it does not count this as right

조회 수: 1 (최근 30일)
Luca Botti
Luca Botti 2020년 3월 22일
답변: Guillaume 2020년 3월 22일
I am submitting this solution to the problem compustCost. it produces the right answer (32.07), however when I submit the this code, the submsion does not count as right, fo you have any idea why?
  댓글 수: 2
darova
darova 2020년 3월 22일
I don't understand
Luca Botti
Luca Botti 2020년 3월 22일
ok I am afraid I am going to say some kind of crap, I just started to get in to this kind of language. I am a real newbe.
However I defined theta as a 2 row matrix [0;0] since the homework is asking me to find J for these value example values of theta.
what do you find odd? I probably I have done something wrong :)

댓글을 달려면 로그인하십시오.

답변 (1개)

Guillaume
Guillaume 2020년 3월 22일
First, don't post screenshots of the code. Simply copy/paste the code as text directly in your code (and then click the button). We can't copy text out of screenshots, it's more work for us to help you if we have to retype your code.
What Darova was pointing out is that X, y and theta are inputs of the function. If you redefine them inside the function, you're just throwing away these inputs wich is certainly not what you're meant to do. Since they're inputs you just use them as they are in your function. Note that this is not particular to matlab, it's the same in any programming language.
Secondly, if the X, y and theta inputs can be vectors or matrices, then almost certainly you should be using .* to do element-wise multiplication.
Also, using both X and x as variable names is begging for trouble, there's a great risk that you'll type one when you mean the other. I'd recommend using more meaningfull variable names.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by