i have multiple inputs of that when put in the only four solves at the bottom only give one output unlike they should
for i = 1 : 80
s(i+1) = i;
Y = sym('Y');
syms S
S = solve (Y==((0.02*i)+0.15),Y);
end
syms P1
syms P2
syms P3
syms P4
P1 = solve (P1==((8*0.85)/((8*S)-1))-(27/(64*(S^2))),P1)
P2 = solve (P2==((8*0.9)/((8*S)-1))-(27/(64*(S^2))),P2)
P3 = solve (P3==((8*0.95)/((8*S)-1))-(27/(64*(S^2))),P3)
P4 = solve (P4==((8*1)/((8*S)-1))-(27/(64*(S^2))),P4)

 Akzeptierte Antwort

madhan ravi
madhan ravi am 18 Nov. 2018
Bearbeitet: madhan ravi am 18 Nov. 2018

1 Stimme

Loop is inefficient so use subs instead:
syms Y P1 P2 P3 P4 s
S = solve (Y==((0.02*s)+0.15),Y);
P1 = solve (P1==((8*0.85)/((8*S)-1))-(27/(64*(S^2))),P1);
P2 = solve (P2==((8*0.9)/((8*S)-1))-(27/(64*(S^2))),P2);
P3 = solve (P3==((8*0.95)/((8*S)-1))-(27/(64*(S^2))),P3);
P4 = solve (P4==((8*1)/((8*S)-1))-(27/(64*(S^2))),P4);
s=1:80;
P1=vpa(subs(P1,s),4)
P2=vpa(subs(P2,s),4)
P3=vpa(subs(P3,s),4)
P4=vpa(subs(P4,s),4)

7 Kommentare

callum roberts
callum roberts am 18 Nov. 2018
The lowercase "s" is giving an error that it is undefined in the first solve
madhan ravi
madhan ravi am 18 Nov. 2018
see edited answer
The output of p1,p2,p3 and p4 are including s in teh answer not giving me mutiple values
P1 =
34/(5*((4*s)/25 + 1/5)) - 27/(64*(s/50 + 3/20)^2)
P2 =
36/(5*((4*s)/25 + 1/5)) - 27/(64*(s/50 + 3/20)^2)
P3 =
38/(5*((4*s)/25 + 1/5)) - 27/(64*(s/50 + 3/20)^2)
P4 =
8/((4*s)/25 + 1/5) - 27/(64*(s/50 + 3/20)^2)
madhan ravi
madhan ravi am 18 Nov. 2018
did you try my answer?
madhan ravi
madhan ravi am 18 Nov. 2018
Bearbeitet: madhan ravi am 18 Nov. 2018
>> syms Y P1 P2 P3 P4 s
S = solve (Y==((0.02*s)+0.15),Y);
P1 = solve (P1==((8*0.85)/((8*S)-1))-(27/(64*(S^2))),P1);
P2 = solve (P2==((8*0.9)/((8*S)-1))-(27/(64*(S^2))),P2);
P3 = solve (P3==((8*0.95)/((8*S)-1))-(27/(64*(S^2))),P3);
P4 = solve (P4==((8*1)/((8*S)-1))-(27/(64*(S^2))),P4);
s=1:80;
P1=vpa(subs(P1,s),4)
P2=vpa(subs(P2,s),4)
P3=vpa(subs(P3,s),4)
P4=vpa(subs(P4,s),4)
P1 =
[ 4.291, 1.391, 0.4337, 0.1203, 0.05, 0.07503, 0.1352, 0.2046, 0.2724, 0.3339, 0.3878, 0.4339, 0.4728, 0.5052, 0.5321, 0.554, 0.5717, 0.5858, 0.5969, 0.6054, 0.6116, 0.616, 0.6188, 0.6202, 0.6205, 0.6198, 0.6183, 0.6161, 0.6133, 0.61, 0.6063, 0.6022, 0.5979, 0.5933, 0.5885, 0.5836, 0.5785, 0.5734, 0.5681, 0.5629, 0.5575, 0.5522, 0.5469, 0.5416, 0.5363, 0.531, 0.5257, 0.5205, 0.5154, 0.5103, 0.5052, 0.5002, 0.4953, 0.4904, 0.4856, 0.4808, 0.4761, 0.4715, 0.4669, 0.4624, 0.458, 0.4536, 0.4493, 0.445, 0.4409, 0.4367, 0.4327, 0.4287, 0.4248, 0.4209, 0.4171, 0.4133, 0.4096, 0.406, 0.4024, 0.3989, 0.3954, 0.392, 0.3886, 0.3853]
P2 =
[ 5.402, 2.16, 1.022, 0.5965, 0.45, 0.4199, 0.4382, 0.4749, 0.5163, 0.5561, 0.5918, 0.6226, 0.6482, 0.6692, 0.6859, 0.6989, 0.7087, 0.7157, 0.7204, 0.723, 0.724, 0.7235, 0.7219, 0.7193, 0.7158, 0.7116, 0.7068, 0.7016, 0.6959, 0.69, 0.6838, 0.6774, 0.6709, 0.6642, 0.6575, 0.6507, 0.6439, 0.637, 0.6302, 0.6235, 0.6167, 0.61, 0.6034, 0.5968, 0.5903, 0.5839, 0.5776, 0.5713, 0.5651, 0.5591, 0.5531, 0.5472, 0.5413, 0.5356, 0.53, 0.5245, 0.519, 0.5137, 0.5084, 0.5032, 0.4981, 0.4931, 0.4882, 0.4833, 0.4786, 0.4739, 0.4693, 0.4648, 0.4604, 0.456, 0.4517, 0.4475, 0.4433, 0.4392, 0.4352, 0.4313, 0.4274, 0.4235, 0.4198, 0.4161]
P3 =
[ 6.513, 2.929, 1.61, 1.073, 0.85, 0.7647, 0.7412, 0.7452, 0.7602, 0.7783, 0.7959, 0.8112, 0.8237, 0.8331, 0.8397, 0.8438, 0.8457, 0.8456, 0.8438, 0.8407, 0.8364, 0.8311, 0.825, 0.8183, 0.811, 0.8033, 0.7953, 0.787, 0.7786, 0.77, 0.7613, 0.7526, 0.7439, 0.7351, 0.7264, 0.7178, 0.7092, 0.7007, 0.6924, 0.6841, 0.6759, 0.6678, 0.6599, 0.6521, 0.6444, 0.6368, 0.6294, 0.6221, 0.6149, 0.6078, 0.6009, 0.5941, 0.5874, 0.5809, 0.5744, 0.5681, 0.5619, 0.5559, 0.5499, 0.544, 0.5383, 0.5326, 0.5271, 0.5217, 0.5163, 0.5111, 0.5059, 0.5009, 0.4959, 0.4911, 0.4863, 0.4816, 0.477, 0.4724, 0.468, 0.4636, 0.4593, 0.4551, 0.4509, 0.4469]
P4 =
[ 7.624, 3.698, 2.198, 1.549, 1.25, 1.11, 1.044, 1.015, 1.004, 1.001, 1.0, 0.9999, 0.9991, 0.997, 0.9936, 0.9887, 0.9826, 0.9754, 0.9673, 0.9583, 0.9487, 0.9386, 0.9281, 0.9173, 0.9062, 0.8951, 0.8838, 0.8725, 0.8612, 0.85, 0.8388, 0.8278, 0.8168, 0.8061, 0.7954, 0.7849, 0.7746, 0.7644, 0.7545, 0.7447, 0.7351, 0.7256, 0.7164, 0.7073, 0.6984, 0.6897, 0.6812, 0.6728, 0.6646, 0.6566, 0.6488, 0.6411, 0.6335, 0.6261, 0.6189, 0.6118, 0.6049, 0.598, 0.5914, 0.5848, 0.5784, 0.5722, 0.566, 0.56, 0.5541, 0.5483, 0.5426, 0.537, 0.5315, 0.5262, 0.5209, 0.5157, 0.5106, 0.5057, 0.5008, 0.496, 0.4913, 0.4866, 0.4821, 0.4776]
>>
callum roberts
callum roberts am 18 Nov. 2018
yup it works thankyou very much for your time
madhan ravi
madhan ravi am 18 Nov. 2018
Anytime :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2018b

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by