You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
hi i am trying to get the output of this loop in one matrix to use it in another function can anyone help me ?
1 view (last 30 days)
Show older comments
Mohamed Atef
on 28 Dec 2022
syms d
v1=1;
z=acos(0.9);
x12=.06;
v=[ 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 .9 1];
for v2=0:0.1:1 ;
sol= solve((v2/.06)*tan(z)*sin(d)==(v2/.06)*cos(d)-((v2*v2)/.06),d);
s=sol;
s2=double(s);
p=(v2/0.06)*sin(s2);
p2=double(p);
end
Accepted Answer
Torsten
on 29 Dec 2022
Edited: Torsten
on 29 Dec 2022
z = acos(0.9);
v = [ 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 .9 1];
% d = -z + acos(v*cos(z)) is (one) solution of (v/0.06)*tan(z)*sin(d)==(v/0.06)*cos(d)-v^2/0.06
% Any d + 2*pi*k (k integer) is also a solution. But since sin(d) is taken later, it doesn't matter.
d = -z+acos(v*cos(z));
p = v/0.06.*sin(d);
plot(v,p)
grid on
2 Comments
Mohamed Atef
on 29 Dec 2022
Edited: Mohamed Atef
on 29 Dec 2022
thank you verymuch . last thing can you tell mehow yo display the point of the peak of the curve at command window @Torsten
Torsten
on 29 Dec 2022
Edited: Torsten
on 29 Dec 2022
syms d v
z = acos(0.9);
d = -z+acos(v*cos(z));
p = v/0.06.*sin(d);
dp = diff(p,v);
format long
vmax = double(solve(dp==0,v));
pmax = double(subs(p,v,vmax));
vmax(2)
ans =
0.590098393995658
pmax(2)
ans =
5.223241718943822
V = [ 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
D = double(subs(d,v,V));
P = V/0.06.*sin(D);
hold on
plot(V,P)
plot(vmax(2),pmax(2),'o')
hold off
grid on

More Answers (1)
VBBV
on 28 Dec 2022
Edited: VBBV
on 28 Dec 2022
k = 1;
for v2=0:0.1:1 ;
sol= solve((v2/.06)*tan(z)*sin(d)==(v2/.06)*cos(d)-((v2*v2)/.06),d);
s=sol;
s2=double(s);
p=(v2/0.06)*sin(s2);
p2{k}=double(p); k = k+1;
end
p2
11 Comments
Mohamed Atef
on 28 Dec 2022
Walter Roberson
on 28 Dec 2022
(updated)
"can you tell me how to convert it to the real values"
I will interpret that as a request to filter out results that have a non-zero imaginary component.
It turns out that the for the solutions that have imaginary component, the imaginary component is negligible, effectively round-off error.
I had to code for a couple of conditions:
- when v2 is 0 (first possible value) then terms on both sides of the equality vanish, and all values of d become valid solutions. I now detect that and inject a marker value of [-inf inf] in place of the infinite set of solutions
- because of the trig, there are a potentially infinite number of solutions offset at different multiples of π . To deal with that, I detect that parameters are introduced into the solution, and I substitute -10 to +10 as the multiple of pi, and give solutions for each of them. In practice because you take sin() of the proposed solutions and do not use the solutions otherwise, and the solutions are integral multiples of pi apart, the sin() maps all of them to the same value. As long as you are sure that you will only sin() or only cos() the solution you could probably substitute just 0 instead of -10:10 and would still get the same solution -- but if at any later point you might use the s2 value in some other way than pure unmodified sin() or pure unmodified cos() then you need the extra generality
format long g
syms d
v1=1;
z=acos(0.9);
x12=.06;
v=[ 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 .9 1];
v2vals = 0:0.1:1;
numv2 = length(v2vals);
for v2idx = 1:numv2
v2 = v2vals(v2idx);
sol = solve((v2/.06)*tan(z)*sin(d)==(v2/.06)*cos(d)-((v2*v2)/.06),d, 'returnconditions', true);
s=sol.d;
if isAlways(s == sol.parameters, 'unknown', 'false')
p2{v2idx} = [-inf inf];
fprintf('solve says all values are solutions, iteration #%d\n', v2idx);
else
if ~isempty(sol.parameters)
K = -10:10;
s = subs(s, sol.parameters, K);
end
s2 = double(s)
p = (v2/0.06)*sin(s2);
dp = double(p);
dp(abs(imag(dp))>1e-10) = [];
p2{v2idx} = real(dp); %get rid of negligible imaginary part
end
end
solve says all values are solutions, iteration #1
s2 =
-61.8022055018118 + 0i -55.5190201946322 + 0i -49.2358348874527 + 0i -42.9526495802731 + 0i -36.6694642730935 + 0i -30.3862789659139 + 0i -24.1030936587343 + 0i -17.8199083515547 + 0i -11.5367230443751 + 0i -5.25353773719555 + 0i 1.02964756998404 + 0i 7.31283287716363 + 0i 13.5960181843432 + 0i 19.8792034915228 + 0i 26.1623887987024 + 0i 32.445574105882 + 0i 38.7287594130616 + 0i 45.0119447202411 + 0i 51.2951300274207 + 0i 57.5783153346003 + 0i 63.8615006417799 + 0i
-64.7635542653724 + 1.13195988485334e-72i -58.4803689581928 + 1.13195988485334e-72i -52.1971836510133 + 1.13195988485334e-72i -45.9139983438337 + 1.13195988485334e-72i -39.6308130366541 + 1.13195988485334e-72i -33.3476277294745 + 1.13195988485334e-72i -27.0644424222949 + 1.13195988485334e-72i -20.7812571151153 + 1.13195988485334e-72i -14.4980718079357 + 1.13195988485334e-72i -8.21488650075615 + 1.13195988485334e-72i -1.93170119357656 + 1.13195988485334e-72i 4.35148411360302 + 1.13195988485334e-72i 10.6346694207826 + 1.13195988485334e-72i 16.9178547279622 + 1.13195988485334e-72i 23.2010400351418 + 1.13195988485334e-72i 29.4842253423214 + 1.13195988485334e-72i 35.767410649501 + 1.13195988485334e-72i 42.0505959566805 + 1.13195988485334e-72i 48.3337812638601 + 1.13195988485334e-72i 54.6169665710397 + 1.13195988485334e-72i 60.9001518782193 + 1.13195988485334e-72i
s2 =
-61.8930700080438 + 0i -55.6098847008642 + 0i -49.3266993936846 + 0i -43.043514086505 + 0i -36.7603287793254 + 0i -30.4771434721458 + 0i -24.1939581649663 + 0i -17.9107728577867 + 0i -11.6275875506071 + 0i -5.3444022434275 + 0i 0.938783063752087 + 0i 7.22196837093167 + 0i 13.5051536781113 + 0i 19.7883389852908 + 0i 26.0715242924704 + 0i 32.35470959965 + 0i 38.6378949068296 + 0i 44.9210802140092 + 0i 51.2042655211888 + 0i 57.4874508283684 + 0i 63.770636135548 + 0i
-64.6726897591405 + 5.6597994242667e-73i -58.3895044519609 + 5.6597994242667e-73i -52.1063191447813 + 5.6597994242667e-73i -45.8231338376017 + 5.6597994242667e-73i -39.5399485304221 + 5.6597994242667e-73i -33.2567632232425 + 5.6597994242667e-73i -26.973577916063 + 5.6597994242667e-73i -20.6903926088834 + 5.6597994242667e-73i -14.4072073017038 + 5.6597994242667e-73i -8.1240219945242 + 5.6597994242667e-73i -1.84083668734461 + 5.6597994242667e-73i 4.44234861983498 + 5.6597994242667e-73i 10.7255339270146 + 5.6597994242667e-73i 17.0087192341941 + 5.6597994242667e-73i 23.2919045413737 + 5.6597994242667e-73i 29.5750898485533 + 5.6597994242667e-73i 35.8582751557329 + 5.6597994242667e-73i 42.1414604629125 + 5.6597994242667e-73i 48.4246457700921 + 5.6597994242667e-73i 54.7078310772717 + 5.6597994242667e-73i 60.9910163844513 + 5.6597994242667e-73i
s2 = 2×21
-61.9854765882647 -55.7022912810851 -49.4191059739055 -43.1359206667259 -36.8527353595464 -30.5695500523668 -24.2863647451872 -18.0031794380076 -11.719994130828 -5.43680882364843 0.846376483531161 7.12956179071075 13.4127470978903 19.6959324050699 25.9791177122495 32.2623030194291 38.5454883266087 44.8286736337883 51.1118589409679 57.3950442481474 63.678229555327
-64.5802831789195 -58.29709787174 -52.0139125645604 -45.7307272573808 -39.4475419502012 -33.1643566430216 -26.881171335842 -20.5979860286624 -14.3148007214829 -8.03161541430327 -1.74843010712369 4.5347552000559 10.8179405072355 17.1011258144151 23.3843111215947 29.6674964287742 35.9506817359538 42.2338670431334 48.517052350313 54.8002376574926 61.0834229646722
s2 = 2×21
-62.0803514502339 -55.7971661430543 -49.5139808358747 -43.2307955286951 -36.9476102215155 -30.6644249143359 -24.3812396071564 -18.0980542999768 -11.8148689927972 -5.53168368561759 0.751501621561994 7.03468692874158 13.3178722359212 19.6010575431008 25.8842428502803 32.1674281574599 38.4506134646395 44.7337987718191 51.0169840789987 57.3001693861783 63.5833546933579
-64.4854083169504 -58.2022230097708 -51.9190377025912 -45.6358523954116 -39.352667088232 -33.0694817810525 -26.7862964738729 -20.5031111666933 -14.2199258595137 -7.93674055233411 -1.65355524515452 4.62963006202507 10.9128153692047 17.1960006763842 23.4791859835638 29.7623712907434 36.045556597923 42.3287419051026 48.6119272122822 54.8951125194618 61.1782978266413
s2 =
-62.1788488958445 - 1.13195988485334e-72i -55.8956635886649 - 1.13195988485334e-72i -49.6124782814854 - 1.13195988485334e-72i -43.3292929743058 - 1.13195988485334e-72i -37.0461076671262 - 1.13195988485334e-72i -30.7629223599466 - 1.13195988485334e-72i -24.479737052767 - 1.13195988485334e-72i -18.1965517455874 - 1.13195988485334e-72i -11.9133664384078 - 1.13195988485334e-72i -5.63018113122825 - 1.13195988485334e-72i 0.653004175951338 - 1.13195988485334e-72i 6.93618948313092 - 1.13195988485334e-72i 13.2193747903105 - 1.13195988485334e-72i 19.5025600974901 - 1.13195988485334e-72i 25.7857454046697 - 1.13195988485334e-72i 32.0689307118493 - 1.13195988485334e-72i 38.3521160190289 - 1.13195988485334e-72i 44.6353013262084 - 1.13195988485334e-72i 50.918486633388 - 1.13195988485334e-72i 57.2016719405676 - 1.13195988485334e-72i 63.4848572477472 - 1.13195988485334e-72i
-64.3869108713397 - 1.13195988485334e-72i -58.1037255641601 - 1.13195988485334e-72i -51.8205402569806 - 1.13195988485334e-72i -45.537354949801 - 1.13195988485334e-72i -39.2541696426214 - 1.13195988485334e-72i -32.9709843354418 - 1.13195988485334e-72i -26.6877990282622 - 1.13195988485334e-72i -20.4046137210826 - 1.13195988485334e-72i -14.121428413903 - 1.13195988485334e-72i -7.83824310672345 - 1.13195988485334e-72i -1.55505779954386 - 1.13195988485334e-72i 4.72812750763572 - 1.13195988485334e-72i 11.0113128148153 - 1.13195988485334e-72i 17.2944981219949 - 1.13195988485334e-72i 23.5776834291745 - 1.13195988485334e-72i 29.8608687363541 - 1.13195988485334e-72i 36.1440540435337 - 1.13195988485334e-72i 42.4272393507132 - 1.13195988485334e-72i 48.7104246578928 - 1.13195988485334e-72i 54.9936099650724 - 1.13195988485334e-72i 61.276795272252 - 1.13195988485334e-72i
s2 =
-62.2825206661972 - 1.13195988485334e-72i -55.9993353590176 - 1.13195988485334e-72i -49.716150051838 - 1.13195988485334e-72i -43.4329647446584 - 1.13195988485334e-72i -37.1497794374788 - 1.13195988485334e-72i -30.8665941302992 - 1.13195988485334e-72i -24.5834088231196 - 1.13195988485334e-72i -18.30022351594 - 1.13195988485334e-72i -12.0170382087605 - 1.13195988485334e-72i -5.73385290158087 - 1.13195988485334e-72i 0.549332405598712 - 1.13195988485334e-72i 6.8325177127783 - 1.13195988485334e-72i 13.1157030199579 - 1.13195988485334e-72i 19.3988883271375 - 1.13195988485334e-72i 25.6820736343171 - 1.13195988485334e-72i 31.9652589414966 - 1.13195988485334e-72i 38.2484442486762 - 1.13195988485334e-72i 44.5316295558558 - 1.13195988485334e-72i 50.8148148630354 - 1.13195988485334e-72i 57.098000170215 - 1.13195988485334e-72i 63.3811854773946 - 1.13195988485334e-72i
-64.2832391009871 - 1.13195988485334e-72i -58.0000537938075 - 1.13195988485334e-72i -51.7168684866279 - 1.13195988485334e-72i -45.4336831794483 - 1.13195988485334e-72i -39.1504978722688 - 1.13195988485334e-72i -32.8673125650892 - 1.13195988485334e-72i -26.5841272579096 - 1.13195988485334e-72i -20.30094195073 - 1.13195988485334e-72i -14.0177566435504 - 1.13195988485334e-72i -7.73457133637082 - 1.13195988485334e-72i -1.45138602919124 - 1.13195988485334e-72i 4.83179927798835 - 1.13195988485334e-72i 11.1149845851679 - 1.13195988485334e-72i 17.3981698923475 - 1.13195988485334e-72i 23.6813551995271 - 1.13195988485334e-72i 29.9645405067067 - 1.13195988485334e-72i 36.2477258138863 - 1.13195988485334e-72i 42.5309111210659 - 1.13195988485334e-72i 48.8140964282455 - 1.13195988485334e-72i 55.097281735425 - 1.13195988485334e-72i 61.3804670426046 - 1.13195988485334e-72i
s2 = 2×21
-62.3936367683603 -56.1104514611808 -49.8272661540012 -43.5440808468216 -37.260895539642 -30.9777102324624 -24.6945249252828 -18.4113396181032 -12.1281543109237 -5.84496900374407 0.438216303435517 6.7214016106151 13.0045869177947 19.2877722249743 25.5709575321539 31.8541428393334 38.137328146513 44.4205134536926 50.7036987608722 56.9868840680518 63.2700693752314
-64.1721229988239 -57.8889376916443 -51.6057523844647 -45.3225670772852 -39.0393817701056 -32.756196462926 -26.4730111557464 -20.1898258485668 -13.9066405413872 -7.62345523420763 -1.34026992702804 4.94291538015154 11.2261006873311 17.5092859945107 23.7924713016903 30.0756566088699 36.3588419160495 42.6420272232291 48.9252125304087 55.2083978375882 61.4915831447678
s2 =
-62.5158858757303 + 0i -56.2327005685507 + 0i -49.9495152613711 + 0i -43.6663299541915 + 0i -37.3831446470119 + 0i -31.0999593398323 + 0i -24.8167740326527 + 0i -18.5335887254732 + 0i -12.2504034182936 + 0i -5.96721811111398 + 0i 0.315967196065604 + 0i 6.59915250324519 + 0i 12.8823378104248 + 0i 19.1655231176044 + 0i 25.4487084247839 + 0i 31.7318937319635 + 0i 38.0150790391431 + 0i 44.2982643463227 + 0i 50.5814496535023 + 0i 56.8646349606819 + 0i 63.1478202678615 + 0i
-64.049873891454 + 1.13195988485334e-72i -57.7666885842744 + 1.13195988485334e-72i -51.4835032770948 + 1.13195988485334e-72i -45.2003179699152 + 1.13195988485334e-72i -38.9171326627356 + 1.13195988485334e-72i -32.6339473555561 + 1.13195988485334e-72i -26.3507620483765 + 1.13195988485334e-72i -20.0675767411969 + 1.13195988485334e-72i -13.7843914340173 + 1.13195988485334e-72i -7.50120612683772 + 1.13195988485334e-72i -1.21802081965813 + 1.13195988485334e-72i 5.06516448752146 + 1.13195988485334e-72i 11.348349794701 + 1.13195988485334e-72i 17.6315351018806 + 1.13195988485334e-72i 23.9147204090602 + 1.13195988485334e-72i 30.1979057162398 + 1.13195988485334e-72i 36.4810910234194 + 1.13195988485334e-72i 42.764276330599 + 1.13195988485334e-72i 49.0474616377786 + 1.13195988485334e-72i 55.3306469449581 + 1.13195988485334e-72i 61.6138322521377 + 1.13195988485334e-72i
s2 = 2×21
-62.6562356719514 -56.3730503647718 -50.0898650575922 -43.8066797504126 -37.523494443233 -31.2403091360535 -24.9571238288739 -18.6739385216943 -12.3907532145147 -6.10756790733511 0.175617399844478 6.45880270702406 12.7419880142037 19.0251733213832 25.3083586285628 31.5915439357424 37.874729242922 44.1579145501016 50.4410998572812 56.7242851644608 63.0074704716403
-63.9095240952329 -57.6263387880533 -51.3431534808737 -45.0599681736941 -38.7767828665145 -32.4935975593349 -26.2104122521554 -19.9272269449758 -13.6440416377962 -7.36085633061659 -1.077671023437 5.20551428374258 11.4886995909222 17.7718848981018 24.0550702052813 30.3382555124609 36.6214408196405 42.9046261268201 49.1878114339997 55.4709967411793 61.7541820483589
s2 = 2×21
-63.7339066953884 -57.4507213882088 -51.1675360810292 -44.8843507738496 -38.60116546667 -32.3179801594905 -26.0347948523109 -19.7516095451313 -13.4684242379517 -7.18523893077211 -0.902053623592525 5.38113168358706 11.6643169907666 17.9475022979462 24.2306876051258 30.5138729123054 36.797058219485 43.0802435266646 49.3634288338442 55.6466141410238 61.9297994482033
-62.8318530717959 -56.5486677646163 -50.2654824574367 -43.9822971502571 -37.6991118430775 -31.4159265358979 -25.1327412287183 -18.8495559215388 -12.5663706143592 -6.28318530717959 0 6.28318530717959 12.5663706143592 18.8495559215388 25.1327412287183 31.4159265358979 37.6991118430775 43.9822971502571 50.2654824574367 56.5486677646163 62.8318530717959
p2
p2 = 1×11 cell array
{[-Inf Inf]} {2×21 double} {2×21 double} {2×21 double} {2×21 double} {2×21 double} {2×21 double} {2×21 double} {2×21 double} {2×21 double} {2×21 double}
Mohamed Atef
on 28 Dec 2022
thank you but i wanted values of (p) to plot curve between p and v how i can show them ?@Walter Roberson
Walter Roberson
on 29 Dec 2022
showing the values of p will not help you to plot the values.
format long g
syms d
v1=1;
z=acos(0.9);
x12=.06;
v=[ 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 .9 1];
v2vals = 0:0.1:1;
numv2 = length(v2vals);
for v2idx = 1:numv2
v2 = v2vals(v2idx);
sol = solve((v2/.06)*tan(z)*sin(d)==(v2/.06)*cos(d)-((v2*v2)/.06),d, 'returnconditions', true);
s=sol.d;
if isAlways(s == sol.parameters, 'unknown', 'false')
p2{v2idx} = [-inf inf];
fprintf('solve says all values are solutions, iteration #%d\n', v2idx);
else
if ~isempty(sol.parameters)
K = -10:10;
s = subs(s, sol.parameters, K);
end
s2 = double(s);
p = (v2/0.06)*sin(s2);
dp = double(p);
dp(abs(imag(dp))>1e-10) = [];
p2{v2idx} = real(dp); %get rid of negligible imaginary part
end
end
solve says all values are solutions, iteration #1
celldisp(p2)
p2{1} =
-Inf Inf
p2{2} =
Columns 1 through 7
1.42852916389563 1.42852916389563 1.42852916389563 1.42852916389563 1.42852916389563 1.42852916389563 1.42852916389563
-1.55929613220185 -1.55929613220185 -1.55929613220185 -1.55929613220185 -1.55929613220185 -1.55929613220185 -1.55929613220185
Columns 8 through 14
1.42852916389563 1.42852916389563 1.42852916389563 1.42852916389563 1.42852916389563 1.42852916389563 1.42852916389563
-1.55929613220185 -1.55929613220185 -1.55929613220185 -1.55929613220185 -1.55929613220185 -1.55929613220185 -1.55929613220185
Columns 15 through 21
1.42852916389563 1.42852916389563 1.42852916389563 1.42852916389563 1.42852916389563 1.42852916389563 1.42852916389563
-1.55929613220185 -1.55929613220185 -1.55929613220185 -1.55929613220185 -1.55929613220185 -1.55929613220185 -1.55929613220185
p2{3} =
Columns 1 through 7
2.68946589395346 2.68946589395346 2.68946589395346 2.68946589395346 2.68946589395346 2.68946589395346 2.68946589395347
-3.21253376717834 -3.21253376717835 -3.21253376717835 -3.21253376717835 -3.21253376717835 -3.21253376717835 -3.21253376717834
Columns 8 through 14
2.68946589395347 2.68946589395346 2.68946589395346 2.68946589395346 2.68946589395347 2.68946589395346 2.68946589395346
-3.21253376717834 -3.21253376717834 -3.21253376717835 -3.21253376717835 -3.21253376717835 -3.21253376717835 -3.21253376717835
Columns 15 through 21
2.68946589395346 2.68946589395347 2.68946589395347 2.68946589395347 2.68946589395347 2.68946589395347 2.68946589395347
-3.21253376717835 -3.21253376717835 -3.21253376717834 -3.21253376717834 -3.21253376717834 -3.21253376717835 -3.21253376717835
p2{4} =
Columns 1 through 7
3.74442009236524 3.74442009236524 3.74442009236524 3.74442009236524 3.74442009236524 3.74442009236524 3.74442009236524
-4.92132280712123 -4.92132280712122 -4.92132280712122 -4.92132280712122 -4.92132280712122 -4.92132280712122 -4.92132280712122
Columns 8 through 14
3.74442009236524 3.74442009236524 3.74442009236524 3.74442009236524 3.74442009236524 3.74442009236524 3.74442009236524
-4.92132280712122 -4.92132280712122 -4.92132280712122 -4.92132280712122 -4.92132280712122 -4.92132280712122 -4.92132280712122
Columns 15 through 21
3.74442009236524 3.74442009236523 3.74442009236523 3.74442009236523 3.74442009236525 3.74442009236525 3.74442009236525
-4.92132280712122 -4.92132280712122 -4.92132280712122 -4.92132280712122 -4.92132280712122 -4.92132280712122 -4.92132280712122
p2{5} =
Columns 1 through 7
4.55157807260173 4.55157807260173 4.55157807260173 4.55157807260173 4.55157807260172 4.55157807260172 4.55157807260172
-6.64384956550125 -6.64384956550125 -6.64384956550125 -6.64384956550125 -6.64384956550125 -6.64384956550125 -6.64384956550125
Columns 8 through 14
4.55157807260172 4.55157807260173 4.55157807260173 4.55157807260173 4.55157807260173 4.55157807260172 4.55157807260173
-6.64384956550125 -6.64384956550125 -6.64384956550125 -6.64384956550125 -6.64384956550125 -6.64384956550125 -6.64384956550125
Columns 15 through 21
4.55157807260173 4.55157807260171 4.55157807260171 4.55157807260174 4.55157807260174 4.55157807260174 4.55157807260174
-6.64384956550125 -6.64384956550125 -6.64384956550125 -6.64384956550125 -6.64384956550125 -6.64384956550125 -6.64384956550125
p2{6} =
Columns 1 through 7
5.06312705848167 5.06312705848167 5.06312705848167 5.06312705848167 5.06312705848167 5.06312705848166 5.06312705848166
-8.33230126613716 -8.33230126613716 -8.33230126613716 -8.33230126613716 -8.33230126613716 -8.33230126613716 -8.33230126613716
Columns 8 through 14
5.06312705848166 5.06312705848166 5.06312705848165 5.06312705848165 5.06312705848165 5.06312705848165 5.06312705848165
-8.33230126613716 -8.33230126613716 -8.33230126613716 -8.33230126613716 -8.33230126613716 -8.33230126613716 -8.33230126613716
Columns 15 through 21
5.06312705848165 5.06312705848165 5.06312705848165 5.06312705848164 5.06312705848164 5.06312705848164 5.06312705848164
-8.33230126613716 -8.33230126613716 -8.33230126613716 -8.33230126613716 -8.33230126613716 -8.33230126613716 -8.33230126613716
p2{7} =
Columns 1 through 7
5.22117971898834 5.22117971898834 5.22117971898834 5.22117971898834 5.22117971898834 5.22117971898833 5.22117971898833
-9.92879057801226 -9.92879057801226 -9.92879057801226 -9.92879057801226 -9.92879057801226 -9.92879057801226 -9.92879057801226
Columns 8 through 14
5.22117971898833 5.22117971898833 5.22117971898833 5.22117971898833 5.22117971898833 5.22117971898833 5.22117971898832
-9.92879057801226 -9.92879057801226 -9.92879057801226 -9.92879057801226 -9.92879057801226 -9.92879057801226 -9.92879057801226
Columns 15 through 21
5.22117971898832 5.22117971898834 5.22117971898831 5.22117971898831 5.22117971898831 5.2211797189883 5.2211797189883
-9.92879057801226 -9.92879057801226 -9.92879057801225 -9.92879057801225 -9.92879057801225 -9.92879057801226 -9.92879057801226
p2{8} =
Columns 1 through 7
4.95045816894628 4.95045816894628 4.95045816894627 4.95045816894627 4.95045816894627 4.95045816894627 4.95045816894626
-11.358039615951 -11.358039615951 -11.358039615951 -11.358039615951 -11.358039615951 -11.3580396159511 -11.358039615951
Columns 8 through 14
4.95045816894626 4.95045816894626 4.95045816894626 4.95045816894625 4.95045816894625 4.95045816894625 4.95045816894625
-11.358039615951 -11.358039615951 -11.358039615951 -11.358039615951 -11.358039615951 -11.358039615951 -11.358039615951
Columns 15 through 21
4.95045816894624 4.95045816894624 4.95045816894624 4.95045816894624 4.95045816894623 4.95045816894623 4.95045816894623
-11.358039615951 -11.358039615951 -11.358039615951 -11.358039615951 -11.358039615951 -11.358039615951 -11.358039615951
p2{9} =
Columns 1 through 7
4.14314576919172 4.14314576919171 4.14314576919171 4.14314576919171 4.1431457691917 4.14314576919175 4.14314576919174
-12.5122317407899 -12.5122317407898 -12.5122317407898 -12.5122317407898 -12.5122317407898 -12.5122317407898 -12.5122317407898
Columns 8 through 14
4.14314576919174 4.14314576919174 4.14314576919175 4.14314576919174 4.14314576919174 4.14314576919175 4.14314576919172
-12.5122317407898 -12.5122317407898 -12.5122317407898 -12.5122317407898 -12.5122317407898 -12.5122317407898 -12.5122317407898
Columns 15 through 21
4.14314576919172 4.14314576919176 4.14314576919176 4.14314576919175 4.14314576919175 4.14314576919175 4.14314576919175
-12.5122317407898 -12.5122317407898 -12.5122317407898 -12.5122317407898 -12.5122317407898 -12.5122317407898 -12.5122317407898
p2{10} =
Columns 1 through 7
2.6207411157518 2.62074111575179 2.62074111575179 2.62074111575179 2.62074111575178 2.62074111575178 2.62074111575178
-13.2128655485556 -13.2128655485556 -13.2128655485556 -13.2128655485556 -13.2128655485556 -13.2128655485556 -13.2128655485556
Columns 8 through 14
2.62074111575177 2.6207411157518 2.62074111575179 2.62074111575179 2.62074111575178 2.62074111575178 2.6207411157518
-13.2128655485556 -13.2128655485556 -13.2128655485556 -13.2128655485556 -13.2128655485556 -13.2128655485556 -13.2128655485556
Columns 15 through 21
2.6207411157518 2.6207411157518 2.62074111575174 2.62074111575174 2.62074111575184 2.62074111575183 2.62074111575183
-13.2128655485556 -13.2128655485556 -13.2128655485556 -13.2128655485556 -13.2128655485556 -13.2128655485556 -13.2128655485556
p2{11} =
Columns 1 through 7
-13.076696830622 -13.076696830622 -13.076696830622 -13.076696830622 -13.0766968306221 -13.0766968306221 -13.076696830622
4.08215599715784e-14 3.67394039744206e-14 3.26572479772628e-14 2.85750919801049e-14 2.44929359829471e-14 2.04107799857892e-14 1.63286239886314e-14
Columns 8 through 14
-13.076696830622 -13.076696830622 -13.076696830622 -13.076696830622 -13.076696830622 -13.076696830622 -13.076696830622
1.22464679914735e-14 8.16431199431569e-15 4.08215599715784e-15 0 -4.08215599715784e-15 -8.16431199431569e-15 -1.22464679914735e-14
Columns 15 through 21
-13.076696830622 -13.076696830622 -13.076696830622 -13.076696830622 -13.076696830622 -13.076696830622 -13.076696830622
-1.63286239886314e-14 -2.04107799857892e-14 -2.44929359829471e-14 -2.85750919801049e-14 -3.26572479772628e-14 -3.67394039744206e-14 -4.08215599715784e-14
There, this code shows them -- but plot() cannot accept this text output to plot with.
Your p{1} is an indication that for v2(1) == 0, that all values of d are solutions. It is not obvious how you want to include that information in the plot.
Earlier I discussed reasoning why for most other v2 values, there should be an infinite number of solutions in sol each separated by an integer multiple of π . With the sol value only being used inside sin() then in theory the integer multiple of π "should" fall out . If you were not doing the double() step first, then it probably would fall out as the symbolic sin() would know to get rid of it. But with you doing the double(s2) then rounding affects the results, which is why in the above display for p2{11} you can see that the bottom row is not constant value.
The reason you get two rows, by the way, is that the equation you are setting up has two solutions for each given multiple of π .
Walter Roberson
on 29 Dec 2022
If we postpone the conversion into double precision and we examine the structure of the results, then we can see that even when we use the different multiples of π that the resuls turn out exactly the same. The celldisp() of the diff() shows all zeros (so all results exactly the sqame) except for the one that is intended to represent "all solutions are valid"
And that means that you can pick one of them
format long g
syms d
v1=1;
z=acos(0.9);
x12=.06;
v=[ 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 .9 1];
v2vals = 0:0.1:1;
numv2 = length(v2vals);
for v2idx = 1:numv2
v2 = v2vals(v2idx);
sol = solve((v2/.06)*tan(z)*sin(d)==(v2/.06)*cos(d)-((v2*v2)/.06),d, 'returnconditions', true);
s=sol.d;
if isAlways(s == sol.parameters, 'unknown', 'false')
p2{v2idx} = [-inf inf];
fprintf('solve says all values are solutions, iteration #%d\n', v2idx);
else
if ~isempty(sol.parameters)
K = -10:10;
s = subs(s, sol.parameters, K);
end
s2 = simplify(expand(s)); %double(s);
p = (v2/0.06)*sin(s2);
dp = p; %double(p);
dp(abs(imag(dp))>1e-10) = [];
p2{v2idx} = real(dp); %get rid of negligible imaginary part
end
end
solve says all values are solutions, iteration #1
celldisp(p2)
p2{1} =
-Inf Inf
p2{2} =

p2{3} =

p2{4} =

p2{5} =

p2{6} =

p2{7} =

p2{8} =

p2{9} =

p2{10} =

p2{11} =

celldisp(cellfun(@(C) diff(C,2), p2, 'uniform', 0))
ans{1} =
[]
ans{2} =

ans{3} =

ans{4} =

ans{5} =

ans{6} =

ans{7} =

ans{8} =

ans{9} =

ans{10} =

ans{11} =

Walter Roberson
on 29 Dec 2022
format long g
syms d
v1=1;
z=acos(0.9);
x12=.06;
v=[ 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 .9 1];
v2vals = linspace(0,1,25);
numv2 = length(v2vals);
for v2idx = 1:numv2
v2 = v2vals(v2idx);
sol = solve((v2/.06)*tan(z)*sin(d)==(v2/.06)*cos(d)-((v2*v2)/.06),d, 'returnconditions', true);
s=sol.d;
if isAlways(s == sol.parameters, 'unknown', 'false')
p2(v2idx,:) = [nan, nan];
fprintf('solve says all values are solutions, iteration #%d\n', v2idx);
else
if ~isempty(sol.parameters)
K = 0;
s = subs(s, sol.parameters, K);
end
s2 = simplify(expand(s)); %double(s);
p = (v2/0.06)*sin(s2);
dp = p; %double(p);
dp(abs(imag(dp))>1e-10) = [];
dp = double(dp);
p2(v2idx, :) = sort(real(dp)); %get rid of negligible imaginary part
end
end
solve says all values are solutions, iteration #1
plot(v2vals, p2)

I added the sort() because the order of the two results was coming out inconsistent.
There are two lines because solve() is finding two solutions each time.
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)