Solving equations with maxima - trigonometry

I can solve the equation bellow normally
sin(b1*(x-c1)) = sin(b2*(x-c2))
b1*(x-c1) = b2*(x-c2)
c2 = x-(b1*(x-c1))/b2
for c1 = 0, b1 = 1, b2 = 1.5, x = pi/2
c2 = (x-(b1*(x-c1))/b2) = 0.523598775598299
But when I try and do this in Maxima see below the answer is completely different what am I doing incorrectly?
kill(all)$
numer:true$
phase1:0; freq1:1; freq2:1.5; x:pi/2; solve(sin(freq1*(x-phase1))=sin(freq2*(x-phase2)),phase2);
Answer I get below

solve usually works only for simple equations, try Solver.
Also, pi (variable) is not the same as %pi (constant).
kill(all)$
load(solver)$
numer:true;
f:sin(freq2*(x-phase2))=sin(freq1*(x-phase1));
phase1:0; freq1:1; freq2:1.5; x:%pi/2; a:Solver([f],[phase2]);
rhs(a[1][1]),numer;
Answer: 0.5235987755982978
Your second question:
kill(all);
f:sin(b1*(x-c1)) - sin(b2*(x-c2))=0;
triginverses:all;
solve(f,c2);

Related

How do I solve this exponential equation on Excel Solver?

100e^0.25*y = 97.5
Solving for y
Using Excel Solver
I tried using empty column entry for y in 'By changing cells' and Set objective function as LHS of above equation (empty column entry in equation included) equal to value of 97.5 in solver.
It gives no solution
How do I do this?
It's a bit ambiguous what you're asking...
Literal math interpretation: 100*(e^0.25)*y = 97.5
Then y = 97.5 / ( 100 * exp(.25)) = .759
My guess of what you want: 100*e^(0.25*y) = 97.5
Then y = ln(97.5/100) / .25 = -.101
Another possibility: (100 * e)^(0.25 * y) = 97.5
Then y = (ln(97.5) / ln(100*e)) / .25 = 3.268
Whatever it is, this doesn't need solver!
You don't really need the solver. Just re-arrange your formula to solve for Y. Since y = b^x is the same as log(b)Y = x (log of Y, with base b)
Your formula above is the same as:
Y = (log(100e)97.5))/.25
(Read aloud, that's log of 97.5, with base 100e, divided by .25
So, Y = 3.268305672
(Bonus points for someone who can tell me how to format this so the Log looks correct)
The question is "How do I solve this exponential equation on Excel Solver?" which is a fair enough question, as it points to trying to understand how to set up solver.
My interpretation of the equation provided is given in this screenshot ...
The solver dialog box is then setup as follows ...
Of note:
This is a non-linear equation and needs GRG Nonlinear. If you choose LP Simplex, it will not pass the linearity test.
Ensure "Make Unconstrained Variables Non-Negative" is not checked.
It provided this result for me ...
A more precise answer can be obtained by decreasing the "Convergence" value on the GRG Non-Linear Options dialog.
A problem this simple can also be solved using Goal Seek.

Would I reverse this calculation?

I have a spreadsheet which works out margin price etc.
I'm wondering if I can reverse my Margin Calculator?
Presently it works out the Margin %
=((I1-F1)-H1-K1-N1)/I1
(I=Net Price, F=Cost, H=Carriage, K=Fees, N=Promotions)
I want to be able to type a Margin % and it calculates the price and if possible add the round up feature? so everything ends in .99.
Using
=ROUNDUP(SUM(I864*M864)+(I864),0.1)-0.01
(M being Margin field) it calculate using the margin, but it differs from the original price
e.g. Price 69.99=19% Margin
Reverse Calculation 19%=66.99
Difference of 3, i'm really confused and cannot get my head around this, can someone please shed some light?
If M1 = ((I1-F1)-H1-K1-N1)/I1 then reverse I1 = (F1+H1+K1+N1)/(1-M1).
This is done using math to change the subject of the formula:
M1 = ((I1-F1)-H1-K1-N1)/I1 / parenthesis not necessary
M1 = (I1-F1-H1-K1-N1)/I1 / multiply out brackets (*1/I1)
M1 = I1/I1 -F1/I1-H1/I1-K1/I1-N1/I1
M1 = 1 -F1/I1-H1/I1-K1/I1-N1/I1 / -1
M1-1 = -F1/I1-H1/I1-K1/I1-N1/I1 / *I1
(M1-1) * I1 = -F1-H1-K1-N1 / *-1
-1*(M1-1) * I1 = -1*(-F1-H1-K1-N1)
(1-M1) * I1 = F1+H1+K1+N1 / /(1-M1)
I1 = (F1+H1+K1+N1)/(1-M1)

Lua: color fading function

I'm trying to create a function that inputs two RGB colors and a percentage then returns a color in-between the two based off of the percentage.
I found the Dec2Hex function somewhere online and figured it would be useful.
Right now I have tried:
function Dec2Hex(nValue) -- http://www.indigorose.com/forums/threads/10192-Convert-Hexadecimal-to-Decimal
if type(nValue) == "string" then
nValue = String.ToNumber(nValue);
end
nHexVal = string.format("%X", nValue); -- %X returns uppercase hex, %x gives lowercase letters
sHexVal = nHexVal.."";
if nValue < 16 then
return "0"..tostring(sHexVal)
else
return sHexVal
end
end
function fade_RGB(colour1, colour2, percentage)
r1, g1, b1 = string.match(colour1, "#([0-9A-F][0-9A-F])([0-9A-F][0-9A-F])([0-9A-F][0-9A-F])")
r2, g2, b2 = string.match(colour2, "#([0-9A-F][0-9A-F])([0-9A-F][0-9A-F])([0-9A-F][0-9A-F])")
r3 = (tonumber(r1, 16)/tonumber(r2, 16))*(percentage)
g3 = (tonumber(g1, 16)/tonumber(g2, 16))*(percentage)
b3 = (tonumber(b1, 16)/tonumber(b2, 16))*(percentage)
return "#"..Dec2Hex(r3).. Dec2Hex(g3)..Dec2Hex(b3)
end
I think I'm headed in the right direction but the math isn't right and I can't figure out how to fix it. Thanks in advance!
No Name's answer is almost right, but he's not merging the two colors based on the percentage.
What you instead want is to do a linear interpolation of the two values (though know that human vision/light wise this isn't how interpolating colors works, but a lot of libraries do it this way because it is easy and works for simple cases).
r3 = tonumber(r1, 16)*(100-percentage)/100.0 + tonumber(r2, 16)*(percentage)/100.0
As you may notice multiplying and dividing the percentages by 100 is kind of tedious, so you may want to pass it in already divided.
If I'm right, the line
r3 = (tonumber(r1, 16)/tonumber(r2, 16))*(percentage)
should be
r3 = math.abs(tonumber(r1, 16) - tonumber(r2, 16))*(percentage/100)
The other similar lines follow the same concept.
EDIT:
r3 = math.min(tonumber(r1, 16), tonumber(r2, 16)) +
math.abs(tonumber(r1, 16) - tonumber(r2, 16)) * (percentage/100)
should yield red for fade_RGB("#FF0000", #0000FF, 0) and blue for fade_RGB("#FF0000", #0000FF, 100).

Write a simple program to solve (x3 - 17x + 12 = 0) by direct substitution

Like the title says, I need to write a simple program to solve (x3 - 17x + 12 = 0) by direct substitution. Can someone explain to me what this even means? I was under the impression that direct substitution required a Y component of some kind? Not really looking for code help, just the logic of it, I suppose.
This is one possible implementation of Pieter's answer.
We can re-write this equation as:
We put an initial value for x in A1 and in A2 we put:
=(A1^3+12)/17
and copy down (earch row is an iteration on the row above)To see how close A2 is to the actual answer in B2 we put:
=A2^3-17*A1+12
and copy down. Here is a sample with 1 in A1:
The function being solved (by direct substitution) is
f: x -> x^3 - 17x + 12
and the value being solved for is 0,
so the equation to be solved is what you have posted. You will repeatedly substitute values for x, and evaluate the function value f(x) until you obtain a value of zero.

How to copy down matrix that references a row in Excel?

I am trying to calculate a few hundred rows of data, solving a system of linear equations using matrices. I am building my matrices based on the row data. I take the inverse of the resultant 3x3 and then multiply twice, once for x's and once for y's. I get 6 variables from this: a,b,c,d,e and f. How can I copy down the example so that is solves for all rows? I am providing the data and then the formulas I am using now. Right now, if I copy down it skips 3 rows or if I copy down with 3 examples it skips 9 rows. I mean I guess I could go an try to insert extra rows into all 300 so I end up with 900 rows, but there has to be an easier way!
I can't figure out how to get my data to populate in here correctly so here is a link: http://codepad.org/qZwua3h9
Note: I split up the matrix rows so you could see them easier, they are not split up on my sheet.
Edit: If anyone can figure out how to paste the example data here I would welcome it so that this post may be of use to someone in the future. I am not sure how long codepad keeps their pastes.
I gave up and came to the conclusion that there is no reasonable amount of effort that will yield the desired results. Not only was the example case only ONE transformation, but the intended case was for 3 transformations - so three times the work. I came up with a Matlab solution in about 15 minutes. I understand that not everyone has access to Matlab though. So, if someone comes up with any reasonable working excel solution, I would welcome the knowledge and mark that answer as the accepted one. Regardless, here is the Matlab script:
M = csvread('pointData.csv');
T1result = zeros(215,6);
T2result = zeros(215,6);
T3result = zeros(215,6);
for i=1:215,
m = [M(i,1) M(i,2) 1; M(i,3) M(i,4) 1; M(i,5) M(i,6) 1];
x = [M(i,7);M(i,9);M(i,11)];
y = [M(i,8);M(i,10);M(i,12)];
xresult = m\x;
yresult = m\y;
T1result(i,:) = [transpose(xresult),transpose(yresult)];
m = [M(i,7) M(i,8) 1; M(i,9) M(i,10) 1; M(i,11) M(i,12) 1];
x = [M(i,13);M(i,15);M(i,17)];
y = [M(i,14);M(i,16);M(i,18)];
xresult = m\x;
yresult = m\y;
T2result(i,:) = [transpose(xresult),transpose(yresult)];
m = [M(i,13) M(i,14) 1; M(i,15) M(i,16) 1; M(i,17) M(i,18) 1];
x = [M(i,19);M(i,21);M(i,23)];
y = [M(i,20);M(i,22);M(i,24)];
xresult = m\x;
yresult = m\y;
T3result(i,:) = [transpose(xresult),transpose(yresult)];
end
LeafId = csvread('extraColumnsForID.csv');
Tresult = [LeafId, T1result, T2result, T3result];
csvwrite('transforms.csv',Tresult);

Resources