I have been trying to write a MATLAB code that can take in any function for optimization with as many variables as the user wants.
function Enter_Optimization_Code clear all clc x=; U=''; n=input('Enter the number of variables= ') U=input('Enter function with variables as x(1), x(2), x(3)..= ','s') start=input('Enter coordinates of the starting point as [1,3,..]= ') for i=1:n x(i)=start(i) end int(U)
The code is asking the user to enter the number of variables they want and then the function they want to optimize (I didnt write the optimization code yet). For now, I want the code to plug in the value of the starting point into the function and spit out the answer.
e.g. I am entering a function that is x(1)+x(2) and start point as [1,2]. This should cause the code to do the calculation of 1+2=3 and print 3. This is what's happening instead:
Enter the number of variables= 2 n = 2 Enter function with variables as x(1), x(2), x(3)..= x(1)+x(2) U = x(1)+x(2) Enter coordinates of the starting point as [1,3,..]= [1,2] start = 1 2 x = 1 x = 1 2 Undefined function 'int' for input arguments of type 'char'. Error in Enter_Optimization_Code (line 17)
Can anybody solve this?