![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/278660/image.png)
it does not count this as right
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/278650/image.png)
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 comentarios
Respuestas (1)
Guillaume
el 22 de Mzo. de 2020
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.
![](https://uk.mathworks.com/matlabcentral/static/rtc/v3/richeditor-converter-1.13.0-SNAPSHOT-19b/shared/RichEditor/CustomPlugins/AnswersToolstrip/images/toolstrip/liveeditor/insert_code_16.png)
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.
0 comentarios
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!