MATLAB Answers

Why is this error comming?

1 次查看(过去 30 天)
Deepak Singh
Deepak Singh2021-10-14
评论: Image Analyst ,2021-10-14
  2 个评论
Deepak Singh
Deepak Singh 2021-10-14
okay.
Here's the code for it"-
clc;
clear;
carb = [80, 65, 30];
prot = [10, 12, 23];
fats = [32, 56, 42];
vit = [70, 37, 58];
carb_ex = 200;
prot_min = 175;
fats_max = 150;
A = [-prot fats];
b = [-prot_min, fats_max];
Aeq = carb;
beq = carb_ex;
lb = [0, 0, 0];
ub = [100, 100, 100];
x = linprog(-vit, A, b, Aeq, beq, lb, ub);

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2021-10-14
We can't run an image. You should have posted your code as code.
It looks like A has 6 elements, whereas b has only 2 elements and needs 6.
  8 个评论
Image Analyst
Image Analyst 2021-10-14
Looks like it expects A to have rows, more than 1. Right now it's a row vector with one row. You can change it into a column vector with 6 rows by doing
A = [-prot, fats]';
Using ' transposes the array changing it from a 6-column row vector into a 6-row column vector. Equivalent to
A = reshape(A, [], 1); % Make into a single column.
or
A = [-prot(:); fats(:)];

请先登录,再进行评论。

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by