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

1 view (last 30 days)
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;
sol= vpasolve([eq1, eq2],[dRF,dLF])
^ 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.

Accepted Answer

Torsten on 16 Jun 2022
Edited: Torsten on 16 Jun 2022
Taking cotd on both sides of the second equation gives
cotd(dRF) = (Ap*w/L+2*cotd(davg(i)))/2
cotd(dLF) = (2*cotd(davg(i))-Ap*w/L)/2
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.
Aly Osman
Aly Osman on 16 Jun 2022
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!