GEtting err0r

Getting error In Code
Unable to perform assignment because dot indexing is not supported for variables of this type.
x=optimvar('x',3,'LowerBound',[0, 0, -inf],'UpperBound',[inf, inf, inf]);
Obj=(x(1)-(2 *x(2))+3*x(3));
A =x(1)+x(2)+x(3)<=7;
B =-x(1)+x(2)-x(3)<=2;
C =3*x(1)-x(2)-2*x(3)==-5;
Problem=optimproblem('Objective',Obj,'ObjectiveSense','maximize');
Problem.Constraints.con_1 = A;
Problem.Constraints.con_2 = B;
Problem.Constraints.con_3 = C;
x0.x=[0 0 0];
[sol,xfval,exitflag,output] = solve(Problem,x0)
Unable to perform assignment because dot indexing is not supported for variables of this type.
pls Guide me

3 个评论

Pls Guide me where i had made mistake
Code works for me here.
x=optimvar('x',3,'LowerBound',[0, 0, -inf],'UpperBound',[inf, inf, inf]);
Obj=(x(1)-(2 *x(2))+3*x(3));
A =x(1)+x(2)+x(3)<=7;
B =-x(1)+x(2)-x(3)<=2;
C =3*x(1)-x(2)-2*x(3)==-5;
Problem=optimproblem('Objective',Obj,'ObjectiveSense','maximize');
Problem.Constraints.con_1 = A;
Problem.Constraints.con_2 = B;
Problem.Constraints.con_3 = C;
x0.x=[0 0 0];
[sol,xfval,exitflag,output] = solve(Problem,x0)
Solving problem using linprog. The dual-simplex algorithm uses a built-in starting point; ignoring supplied X0. Optimal solution found.
sol = struct with fields:
x: [3×1 double]
xfval = 17.4000
exitflag =
OptimalSolution
output = struct with fields:
iterations: 1 constrviolation: 0 message: 'Optimal solution found.' algorithm: 'dual-simplex' firstorderopt: 8.8818e-16 solver: 'linprog'
sol.x
ans = 3×1
1.8000 0 5.2000
Jan
Jan 2022-9-15
@Vivek: Please post the complete error message. Then we can see, in which line the code fails.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2022-9-15
编辑:Walter Roberson 2022-9-15

1 个投票

you have an existing numeric variable named x0 and so you not permitted to assign to x0.x because numeric variables cannot use dot indexing.
This is the kind of problem that using functions instead of scripts is designed to solve.

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by