This example shows how to pass a vector of guess values to either the Maximize or Minimize functions.
1. Define function f(x).
2. Define x as a vector of guess values.
3. Pass vector x as an argument to the Maximize function.
The error occurs because PTC Mathcad expects x to be a single value and not a vector.
To avoid this error, we need to iterate over the guess values and send them one by one to the Maximize function, as shown below.
4. Use the range operator to define a vector of guess values.
5. Define two new functions to perform maximize and minimize on function f(x).
6. Write a short program to iterate through the guess values and calculate the maximum and minimum for that guess value and save the result to vectors maximums and minimums, respectively.
You can achieve the same results using the vectorization operator, as follows:
Both Ms and Qs return a vector of two 7-element vectors containing the calculated maximums and minimums.
7. Define variable j as the length of the returned vector of maximum values.
8. Plot function f(x) along with the maximum and minimum points returned by the program.
9. Plot function f(x) along with the maximum and minimum points returned by the vectorization operator.