x1 = 0:5; %tank1 capicity
x2 = 0:10; %tank2 capicity
x3 = 0:20; %tank3 capicity
y1 = 2 %L/min pipe 1
y2 = 1 %L/min pipe 2
y3 = 0.5 %L/min pipe 3
v1 = 0 ; v2 = 0; v3 = 0;
while length(v1) < 3
v1 = x1+y1;
while length(v2) < 10
v2 = v1-(x2+y2);
while length(v3) < 20
v3 = v2-(x3+y3);
end
end
end
Why there is an error of my code it calculat v2 and v3 because of the size what can i do if i want my problem solved . Thank you

1 commentaire

DGM
DGM le 12 Fév 2023
In order to make your code do what you want it to do, we need to know what you want it to do. That's not clear.
Upon first being created, v1 will always be 6 elements long. The outer loop will always be satisfied in one pass, so it really doesn't need to exist at all. The next loops will fail because you're trying to subtract a 11x1 vector from a 6x1 vector. I don't know how you propose to do that. Do you expect the result to be another vector, or should it be a matrix? If it's to be a matrix, should it be 11x6 or 6x11? If it's to be a matrix, then the conditional test for the second loop is probably either wrong or superfluous. The third loop bears the same questions.

Connectez-vous pour commenter.

Réponses (1)

Here are a few points to be considered in the code.
Size (length) of v1 is different from the size of v2, and similarly, the size (length of ) of v2 is ddifferent from the size of v3.
x1 = 0:5; %tank1 capicity
x2 = 0:10; %tank2 capicity
x3 = 0:20; %tank3 capicity
y1 = 2 %L/min pipe 1
y1 = 2
y2 = 1 %L/min pipe 2
y2 = 1
y3 = 0.5 %L/min pipe 3
y3 = 0.5000
v1 = 0 ; v2 = 0; v3 = 0;
v1 = x1+y1
v1 = 1×6
2 3 4 5 6 7
length(v1)
ans = 6
length(x2)
ans = 11
v2 = v1-(x2+y2)
Arrays have incompatible sizes for this operation.
Another concern is x1, x2, x3 are capacity (what is their unit? in L or what?) while y1, y2, y3 are L/min flow rate. Therefore, they are not compatible as they are put into the code. The time has to be included.

1 commentaire

DGM
DGM le 12 Fév 2023
I think you just hit the nail on the head. The loops as given are probably irrelevant to the conceptual problem that actually needs to be solved. I'm inclined to doubt that x1,x2,x3 should even be vectors at all. This is probably a basic calculus problem that's been obfuscated.

Connectez-vous pour commenter.

Commenté :

DGM
le 12 Fév 2023

Community Treasure Hunt

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

Start Hunting!

Translated by