Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Problem with the code

1 Ansicht (letzte 30 Tage)
Tobias Pekola
Tobias Pekola am 9 Sep. 2020
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
Hey i got this code and trying to make a graph out of it in Matlab but it wont work, do anyone know why it wont accept it?
f = @(x) 51*x - ((x^2 + x + 3/100)/(2*x + 1))^7 - 17*x*exp(-x)
x= 0:0.1:5
plot(x,y(x))
this is what i get
Error: File: Matlab_labb1.m Line: 26 Column: 4
Invalid expression. Check for missing or extra characters.

Antworten (1)

Rik
Rik am 9 Sep. 2020
Bearbeitet: Rik am 9 Sep. 2020
You should check the rest of the file, because this is not the part of your code that will trigger that issue. There are some things that will trigger an error:
  • In your call to plot you're using y, but your function is defined as f.
  • You are using matrix products, divisions, and powers, but your input is a vector. If you want element-wise operations replace ^ / and * by .^ ./ and .*.
  • This one will not trigger an error, but is still worth noting: you didn't put semicolons at the end of your lines to supress the output.
  2 Kommentare
Tobias Pekola
Tobias Pekola am 9 Sep. 2020
Could you write the correct code so i can see where exactly i should put the dots?
Rik
Rik am 9 Sep. 2020
f = @(x) 51*x - ((x^2 + x + 3/100)/(2*x + 1))^7 - 17*x*exp(-x)
% ^ ^ ^ ^ ^ ^ ^
% all these should be replaced with the element-wise version
(17*x is fine, because 17 is a scalar)

Diese Frage ist geschlossen.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by