How to solve and store a system of non-linear equations with an array of outputs?

2 ビュー (過去 30 日間)
Aly Osman
Aly Osman 2022 年 6 月 16 日
コメント済み: Aly Osman 2022 年 6 月 16 日
I have a system where I have two equations and two unknowns shown below. The unkowns are dRF and dLF and I want to solve for dRF and dLF for each value of davg. I plan on keeping Ap constant to avoid some complexity for now, but eventually would want to find a way to where I can treat both Ap and davg as independent variables by setting a range of values for them and seeing what values for dRF and dLF are produced. So my first thought was to use linsolve, however since these equations aren't linear, after some research I found that vpasolve would help with this situation. Using vpasolve, I was able to get an output for dRF and dLF when using a single value for Ap and davg, however the outputs for dLF and dRF are extremely large, even though computationally when plugged back in, they produce the correct Ap and davg, but in reality these values for dLF and dRF should be b/w 0 to 45 deg since they are what make up davg. However, I found that when adding 180 to dRF and subtracting 180 from dLF, the values are much more logical and subbing them back into the equations, everything checks out.
So then when I wanted to see what dLF and dRF would be depending on davg, putting an array for davg resulted in an error saying "More equations than variables is only supported for polynomial systems.", so at this point I'm kinda stuck on where to go about this. Do I have to do a for loop potentially to account for the changing value for davg? Because I know that If I change the value for davg one by one instead of setting it up as an array, I get different outputs. I tried a for loop seen in the batch of code below, which did produce different values for dLF and dRF, which is great however I can't store these results in an array for dLF and dRF seperately, which is an issue. I also want to find a way to take these stored values and add 180 to dRF and subtract 180 from dLF for better presentation. Would very much appreciate any assistance with this, especially if there's another method that's a bit more intuitive than vpasolve. Fsolve didn't work out well for me with the guesses you have to put in, so vpasolve at least gets me accurate-ish results, but has its issues with storing and outputting obnoxious angle representations instead of something b/w 0 to 90 deg.
clear; clc;
Ap= 1.5;
davg= (linspace(0,30,100));
%davg= 30; % Test with one value
w= 52;
L= 60;
syms dRF dLF
for i= 1:length(davg)
eq1=(cotd(dRF)-cotd(dLF))/(w/L)== Ap;
eq2=acotd((cotd(dRF)+cotd(dLF))/2)==davg(i);
sol= vpasolve([eq1, eq2],[dRF,dLF])
end
^ Output when using 30 deg. for davg. Like I said, computationally it makes sense, but these values should really be between 0 to 45 deg, which they happen to be when adding 180 to dRF and subtracting 180 from dLF.

採用された回答

Torsten
Torsten 2022 年 6 月 16 日
編集済み: Torsten 2022 年 6 月 16 日
Taking cotd on both sides of the second equation gives
cotd(dRF)-cotd(dLF)=Ap*w/L;
cotd(dRF)+cotd(dLF)=2*cotd(davg(i));
Thus
cotd(dRF) = (Ap*w/L+2*cotd(davg(i)))/2
cotd(dLF) = (2*cotd(davg(i))-Ap*w/L)/2
Thus
dRF = acotd( (Ap*w7L+2*cotd(davg(i)))/2 )
dLF = acotd( (2*cotd(davg(i))-Ap*w/L)/2 )
No need to use solve or vpasolve.
  4 件のコメント
Torsten
Torsten 2022 年 6 月 16 日
w= 52;
L= 60;
n = 20;
davg= linspace(0,30,n);
Ap= linspace(0,1,n).';
dRF = acotd( (Ap*w/L+2*cotd(davg))/2 )
dRF = 20×20
0 1.5789 3.1579 4.7368 6.3158 7.8947 9.4737 11.0526 12.6316 14.2105 15.7895 17.3684 18.9474 20.5263 22.1053 23.6842 25.2632 26.8421 28.4211 30.0000 0 1.5780 3.1539 4.7279 6.3000 7.8702 9.4384 11.0048 12.5694 14.1322 15.6933 17.2527 18.8106 20.3669 21.9217 23.4751 25.0272 26.5781 28.1278 29.6765 0 1.5770 3.1500 4.7191 6.2843 7.8457 9.4034 10.9574 12.5078 14.0547 15.5983 17.1385 18.6756 20.2097 21.7410 23.2695 24.7954 26.3189 27.8401 29.3593 0 1.5760 3.1460 4.7103 6.2687 7.8215 9.3686 10.9104 12.4468 13.9781 15.5043 17.0258 18.5426 20.0549 21.5631 23.0672 24.5675 26.0643 27.5578 29.0482 0 1.5750 3.1421 4.7015 6.2532 7.7973 9.3341 10.8638 12.3864 13.9022 15.4115 16.9144 18.4113 19.9024 21.3879 22.8682 24.3436 25.8143 27.2807 28.7431 0 1.5740 3.1382 4.6927 6.2377 7.7734 9.2999 10.8175 12.3266 13.8272 15.3198 16.8045 18.2819 19.7521 21.2155 22.6725 24.1234 25.5687 27.0087 28.4438 0 1.5730 3.1343 4.6840 6.2223 7.7495 9.2659 10.7717 12.2673 13.7529 15.2291 16.6960 18.1541 19.6039 21.0457 22.4799 23.9070 25.3274 26.7417 28.1502 0 1.5720 3.1304 4.6753 6.2070 7.7258 9.2321 10.7263 12.2086 13.6795 15.1394 16.5888 18.0281 19.4578 20.8784 22.2904 23.6942 25.0904 26.4795 27.8621 0 1.5710 3.1265 4.6666 6.1918 7.7023 9.1986 10.6812 12.1504 13.6068 15.0508 16.4830 17.9038 19.3139 20.7137 22.1039 23.4849 24.8575 26.2221 27.5793 0 1.5701 3.1226 4.6580 6.1766 7.6789 9.1653 10.6365 12.0928 13.5348 14.9632 16.3784 17.7811 19.1719 20.5514 21.9203 23.2791 24.6286 25.9692 27.3018
dLF = acotd( (2*cotd(davg)-Ap*w/L)/2 )
dLF = 20×20
0 1.5789 3.1579 4.7368 6.3158 7.8947 9.4737 11.0526 12.6316 14.2105 15.7895 17.3684 18.9474 20.5263 22.1053 23.6842 25.2632 26.8421 28.4211 30.0000 0 1.5799 3.1619 4.7458 6.3316 7.9195 9.5092 11.1009 12.6944 14.2897 15.8868 17.4856 19.0861 20.6882 22.2918 23.8968 25.5033 27.1110 28.7199 30.3299 0 1.5809 3.1658 4.7547 6.3476 7.9444 9.5450 11.1495 12.7578 14.3698 15.9853 17.6044 19.2268 20.8525 22.4813 24.1131 25.7477 27.3849 29.0246 30.6665 0 1.5819 3.1698 4.7637 6.3636 7.9694 9.5811 11.1986 12.8218 14.4507 16.0850 17.7247 19.3695 21.0194 22.6740 24.3331 25.9965 27.6640 29.3352 31.0099 0 1.5829 3.1738 4.7728 6.3797 7.9946 9.6174 11.2481 12.8865 14.5325 16.1859 17.8466 19.5143 21.1888 22.8697 24.5569 26.2498 27.9483 29.6519 31.3602 0 1.5839 3.1778 4.7818 6.3959 8.0199 9.6540 11.2980 12.9518 14.6152 16.2881 17.9702 19.6612 21.3608 23.0687 24.7845 26.5078 28.2381 29.9749 31.7178 0 1.5849 3.1819 4.7909 6.4121 8.0455 9.6909 11.3484 13.0178 14.6989 16.3915 18.0954 19.8102 21.5355 23.2710 25.0162 26.7705 28.5334 30.3044 32.0827 0 1.5859 3.1859 4.8001 6.4285 8.0711 9.7281 11.3992 13.0844 14.7835 16.4962 18.2223 19.9614 21.7130 23.4767 25.2519 27.0380 28.8345 30.6404 32.4551 0 1.5869 3.1899 4.8092 6.4449 8.0970 9.7655 11.4505 13.1517 14.8691 16.6023 18.3510 20.1148 21.8933 23.6858 25.4918 27.3106 29.1414 30.9833 32.8354 0 1.5879 3.1940 4.8184 6.4614 8.1230 9.8033 11.5022 13.2197 14.9556 16.7096 18.4814 20.2705 22.0764 23.8985 25.7360 27.5883 29.4543 31.3331 33.2236
Aly Osman
Aly Osman 2022 年 6 月 16 日
Dang I feel like an idiot... I appreciate it, that is way easier than I anticipated. Guess I was just overcomplicating everything to start with.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by