0

Lets say i have a symbolic function of array[2 2]. Each element represents a function. Then i converted it with matlabFunction() function into function handler. It is all okay up to now. I can get 2x2 answer matrix for example when i input f(1,1). How can i input an vector instead of putting manually 1 and 1. For example i want to define x0=[1 1] and then put f(x0). Each time i get Not enough input arguments. It tries to put 1 to x and then again 1 to x and give to answers. But because there is one more variable called y it gives not enough input argument error. Any suggestion? Basically i want to create f(x), where f and x are matrices. So it becomes system of equation.

For example:

variable1= [1 1]

 jac= @(a,b)reshape([b,a.*2.0+a.^2.*b.^2.*3.0,a+b.*2.0,a.^3.*b.*2.0],[2,2])
 jac(variable[1 1])
Not enough input arguments.

Error in symengine>@(a,b)reshape([b,a.*2.0+a.^2.*b.^2.*3.0,a+b.*2.0,a.^3.*b.*2.0],[2,2])

but when

jac(1,1)

ans =

     1     3
     5     2
4
  • Please include that symbolic function and your code in your post Commented Nov 24, 2017 at 15:03
  • @SardarUsama Done Commented Nov 24, 2017 at 15:06
  • Just copy this variable1= [1 1] jac= @(a,b)reshape([b,a.*2.0+a.^2.*b.^2.*3.0,a+b.*2.0,a.^3.*b.*2.0],[2,2]) jac(variable[1 1]) and it will work. After put jac(1,1) to recreate my problem, i also edited the question you can copy from there also Commented Nov 24, 2017 at 15:16
  • Thanks let me check now Commented Nov 24, 2017 at 15:17

1 Answer 1

0

Define your function with one variable instead of two. i.e.

jac = @(x) reshape([x(2), x(1).*2.0+x(1).^2.*x(2).^2.*3.0, ...
   x(1)+x(2).*2.0, x(1).^3.*x(2).*2.0], [2,2]);

Now you can give it input as jac(variable1) which, as expected, returns:

ans =

     1     3
     5     2

% where variable1 = [1 1]

but since you get that anonymous function as a result of applying matlabFunction(), so you need to make the respective changes in your making of symbolic function i.e. use syms x instead of syms a b and replace a with x(1) and b with x(2) in your code.

Sign up to request clarification or add additional context in comments.

8 Comments

But this function comes from the matlab, i did not define it. It is a long code that is why i gave a part of it. But everything should be automated. Is there a way that i make matlab define existed function as one variable as you suggested?
Because the code takes derivative of input function, there has to be different variable names to get its jacobian function?
@ssovukluk as you wrote you converted your function using matlabFunction, if you show the function that you had before conversion, it can be possible to define it in terms of one variable
@ssovukluk You can fix that by using syms x instead of syms a b and replacing a with x(1) and b with x(2) in your code. If you do that, I am very positive that your problem will be fixed
@ssovukluk Seems like an interesting AI. Good luck with your work!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.