'Index exceeds the number of array elements. Index must not exceed 1
I wanted to convert anonymous function to a symbolic function.
I have something like
f = @(x)4*(3/4*pi-x(1))-7*x(3)
g = sym(f)
but I always get Index exceeds the number of array elements. Index must not exceed 1. How to fix this?
My x has usually size 8,1 but that shouldn't be relevant i guess Do I need to convert my x to sym as well or?
Solution 1:[1]
In your anonymous function f, x is defined to have minimum three indices and hence sym(f) cannot be used to convert it to sym.
Instead, you can call f with a symbolic variable x of size 1x3 like this:
g = f(sym('x',[1,3]));
which gives:
>> g
g =
3*pi - 7*x3 - 4*x1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sardar Usama |
