Adding a function with a specific value

4 visualizaciones (últimos 30 días)
Max Olsen
Max Olsen el 9 de Mzo. de 2021
Comentada: Max Olsen el 10 de Mzo. de 2021
Hello. I am trying to add a simple value to a function, but it rejects me every time. I think i've tried every noob idea, and was all out of luck. What am i missing?
f=@(x) x^4-7*x^3+9*x^2+7*x-5;
f+10
  2 comentarios
the cyclist
the cyclist el 9 de Mzo. de 2021
Which of the following is what you want?
  • Define a new function such that f2(x) is always 10 greater than f(x), for all values of x
  • Find the value of f(x) at a particular value of x, and add 10 to that
  • Something else [please describe]
Jan
Jan el 9 de Mzo. de 2021
Editada: Jan el 9 de Mzo. de 2021
Because the code is not working, we cannot guess, what you want to achieve.
Remember to post a copy of the error message, if you get one.

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 9 de Mzo. de 2021
You define f as a function handle. Then you have to call it with an argument also:
f = @(x) x^4 - 7 * x^3 + 9 * x^2 + 7 * x - 5;
f(5) + 10 % 15
Or do you want to create another function?
g = @(x) f(x) + 10
g(5) % Of course also 15
  1 comentario
Max Olsen
Max Olsen el 10 de Mzo. de 2021
I feel like i tried that already without abything happening, but somehow this helped at doing exactly what i wanted (I wanted to use fzero to find the values at where the function was at -10, but that needed a function that had both the old function and the +10)

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by