Why is this error comming?

2 comentarios

John D'Errico
John D'Errico el 14 de Oct. de 2021
As is too often the case, someone has posted a picture of their code. Now, for someone to test out what you did, we need to type in evertything, with no errors on our part. And that will take care and a fair amount of time.
Instead, you could have paste in your data directly, whcih would have taken fewer step on your part, and LESS time for you too. If you paste in text directly, then we can copy and paste it directly into MATLAB. ANd that would allow me to identify exactly what you did wrong in a few seconds.
So what you have done is to make it more difficult for someone to help you.
Is there a good reason why you want to make it more difficult to get help? Perhaps someone may bother to type in your code. Not me. Sorry.
Deepak Singh
Deepak Singh el 14 de Oct. de 2021
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);

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 14 de Oct. de 2021

0 votos

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 comentarios

Deepak Singh
Deepak Singh el 14 de Oct. de 2021
Code:-
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);
Deepak Singh
Deepak Singh el 14 de Oct. de 2021
Pls now check and please answer again.
Deepak Singh
Deepak Singh el 14 de Oct. de 2021
Coud'nt understand this :- It looks like A has 6 elements, whereas b has only 2 elements and needs 6.
Deepak Singh
Deepak Singh el 14 de Oct. de 2021
what to add
?
Image Analyst
Image Analyst el 14 de Oct. de 2021
Change this
b = [-prot_min, fats_max];
so it has 6 items. I don't know what order you want them since you didn't give the equation. Maybe it's
b = [-prot_min;-prot_min;-prot_min; fats_max;fats_max;fats_max];
but I really have no idea. Please give the equations you're trying to fit/model.
Deepak Singh
Deepak Singh el 14 de Oct. de 2021
I tried you gave above but a new error came:-
Code:-
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;-prot_min;-prot_min; fats_max;fats_max;fats_max];
Aeq = carb;
beq = carb_ex;
lb = [0, 0, 0];
ub = [100, 100, 100];
x = linprog(-vit, A, b, Aeq, beq, lb, ub);
Error:-
Error using linprog (line 253)
The number of rows in A must be the same as the number of elements of b.
Error in q2 (line 16)
x = linprog(-vit, A, b, Aeq, beq, lb, ub);
Note:- I coudn't enter and write error in new so wrote in this.
Pls understand.
I have sent you the question so i solved it using linprog and got error so aksed here.
as well as there is a error in last line pls check that also.
Deepak Singh
Deepak Singh el 14 de Oct. de 2021
So as given i question we have to find hw much kilogram of each food item the person should consume so as to have maximum intake of vitamins by using any appropriate built in function present in matlab so i did with linprog and u can see the error.
Image Analyst
Image Analyst el 14 de Oct. de 2021
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(:)];

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Productos

Versión

R2021a

Etiquetas

Preguntada:

el 14 de Oct. de 2021

Comentada:

el 14 de Oct. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by