I am trying to solve multiple equations in an array but am getting too many answers for one equation.
>> P = sym('P', [1 3]);
>> V = sym('V', [1 3]);
>> R_ON = [1 2 3];
>> P = ((200-V)./100).*V==(V.^2)./R_ON
P =
[ -V1*(V1/100 - 2) == V1^2, -V2*(V2/100 - 2) == V2^2/2, -V3*(V3/100 - 2) == V3^2/3]
>> solve(P).V1
ans =
0
0
200/101
200/101
0
0
200/101
200/101
Why is the solution giving me repeated values and 8 solutions? There should only be the two solutions, 0 and 200/101. Thanks in advance!

 Respuesta aceptada

Displaay at all the solutions to understand what solve is doing —
P = sym('P', [1 3]);
V = sym('V', [1 3]);
R_ON = [1 2 3];
P = ((200-V)./100).*V==(V.^2)./R_ON
P = 
% P =
% [ -V1*(V1/100 - 2) == V1^2, -V2*(V2/100 - 2) == V2^2/2, -V3*(V3/100 - 2) == V3^2/3]
S = solve(P)
S = struct with fields:
V1: [8×1 sym] V2: [8×1 sym] V3: [8×1 sym]
S.V1
ans = 
S.V2
ans = 
S.V3
ans = 
.

4 comentarios

Josh Frisby
Josh Frisby el 2 de Mayo de 2021
Okay, so it is really combinding all 3 equations into one and trying to solve? How do I get it to solve each equation independently? Like solve: -V1*(V1/100 - 2) == V1^2 for V1 then solve -V2*(V2/100 - 2) == V2^2/2 for V2 and finally solve -V3*(V3/100 - 2) == V3^2/3 for V3?
Star Strider
Star Strider el 2 de Mayo de 2021
It is not possible to solve for them independently, since ‘V’ and ‘P’ are vectors.
Solve for ‘V’ then choose the element of the solution that you want.
.
Well your answer and comment put me on the right path at least. The code below fully encapsulates what I was trying to achieve. I encorporated a for loop to solve for each equation independly of each other. Thanks.
sympref('FloatingPointOutput',true); %store values in symbol type as floats
V_DS = sym('V_DS', [1 41]); %define V_DS as array of symbols
V = sym('V', [1 41]); %define V as array of symbols
P = sym('P', [1 41]); %define P as array of symbols
T=linspace(0,200,41); %define temps in range from 0-200 increasing by increments of 5
R_ON = 0.0133.*T+1.667; %create an array of R_ON values for each temp
assume(V>0); %only store solutions greater than 0 for V
V = ((200-V)./100).*V==(V.^2)./R_ON; %create an array of voltage equations for each R_ON value
for i = 1:41
V_DS(i) = solve(V(i)); %solve and store each voltage equation for V
P(i) = (V_DS(i).^2)./R_ON(i); %solve for power associated with each voltage
end
%create table
Table = table(T',R_ON',double(V_DS'),double(P'), 'VariableNames', {['Temp(' char(176) 'C)'],'R_ON(Ω)','V_DS(V)','P(W)'})
%create plot with settings
figure
hold on;
plot(T,double(P),'Color','b','Marker','+','MarkerFaceColor','#A2142F','MarkerEdgeColor','#A2142F');
xlabel("Temperature (" + char(176) + "C)",'FontSize',14,'Color','#7E2F8E');
ylabel("Power (W)",'FontSize',14,'Color','#7E2F8E');
title("Power (W) VS Temperature (" + char(176) + "C)",'Color','#7E2F8E');
set(gca,'FontSize',20,'XColor','#7E2F8E','YColor','#7E2F8E');
Star Strider
Star Strider el 6 de Mayo de 2021
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 2 de Mayo de 2021

Comentada:

el 6 de Mayo de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by