equation-solving

Is it possible to solve an algebraic equation in R?

谁说我不能喝 提交于 2020-12-01 10:54:46
问题 I want to find the solution of: -x^3+6*x^2+51*x+44=0 but with R. Is it possible? I found the package Ryacas, but nobody seems to be able to make it work. May sound trivial, but I'm not able to find an easy way to do this... Do you have an alternative? Thanks guys! 回答1: You can use polynom package: library(polynom) p <- polynomial(c(44,51,6,-1)) # 44 + 51*x + 6*x^2 - x^3 solve(p) # [1] -4 -1 11 But you simply can use the function polyroot from base package: polyroot(c(44,51,6,-1)) # [1] -1+0i

Is it possible to solve an algebraic equation in R?

╄→尐↘猪︶ㄣ 提交于 2020-12-01 10:53:26
问题 I want to find the solution of: -x^3+6*x^2+51*x+44=0 but with R. Is it possible? I found the package Ryacas, but nobody seems to be able to make it work. May sound trivial, but I'm not able to find an easy way to do this... Do you have an alternative? Thanks guys! 回答1: You can use polynom package: library(polynom) p <- polynomial(c(44,51,6,-1)) # 44 + 51*x + 6*x^2 - x^3 solve(p) # [1] -4 -1 11 But you simply can use the function polyroot from base package: polyroot(c(44,51,6,-1)) # [1] -1+0i

sympy unknown assignment

戏子无情 提交于 2020-03-28 06:39:13
问题 I'm trying to create a python program for solving equations: from sympy import symbols, Eq, solve list1 = ['x', 'y'] #<--- Letters of the user input list1[0] = symbols(list1[0]) #<--- Assignment of the unknown x list1[1] = symbols(list1[1]) #<--- Assignment of the unknown y eq1 = Eq(x*2 - 5*x + 6 + y, 0) #<--- Equation res = solve(eq1, dict=True) #<--- Solving print(res) I want assign a value to the first and the second object of the 'list1', in this case 'x = symbols('x')' and 'y = symbols(

Matlab Solve System of Equations with Quantized Variables

强颜欢笑 提交于 2020-01-13 06:48:25
问题 I am trying to use solve() to solve a system of equations of the following form eq1=a1x+a2y; eq2=b1x+b2y; where a1 = .05 for values of x<5 , .1 for values of 5 Is there a way to solve for this using solve? As in sol = solve(eq1,eq2); 回答1: I'm not sure what you're trying to do here. Can you please post a real example (with numbers) and what you would like the output to be? I think you're trying to solve linear simultaeneous equations. Assuming that is what you are trying to do: I would suggest

solving a sparse non linear system of equations using scipy.optimize.root

一曲冷凌霜 提交于 2020-01-07 06:41:55
问题 I want to solve the following non-linear system of equations. Notes the dot between a_k and x represents dot product . the 0 in the first equation represents 0 vector and 0 in the second equation is scaler 0 all the matrices are sparse if that matters. Known K is an n x n (positive definite) matrix each A_k is a known (symmetric) matrix each a_k is a known n x 1 vector N is known (let's say N = 50). But I need a method where I can easily change N. Unknown (trying to solve for) x is an n x 1 a

solving a sparse non linear system of equations using scipy.optimize.root

◇◆丶佛笑我妖孽 提交于 2020-01-07 06:41:49
问题 I want to solve the following non-linear system of equations. Notes the dot between a_k and x represents dot product . the 0 in the first equation represents 0 vector and 0 in the second equation is scaler 0 all the matrices are sparse if that matters. Known K is an n x n (positive definite) matrix each A_k is a known (symmetric) matrix each a_k is a known n x 1 vector N is known (let's say N = 50). But I need a method where I can easily change N. Unknown (trying to solve for) x is an n x 1 a

Solve finds wrong solution?

徘徊边缘 提交于 2020-01-07 05:23:46
问题 I have this equation in x and y: (x + y)^(1/2) - 6*y*(x + y)^5 - (x + y)^6 + (x - 1)/(2*(x + y)^(1/2)) = 0. Now I call the solver: R_c = @(y)solve((x + y)^(1/2) - 6*y*(x + y)^5 - (x + y)^6 + (x - 1)/(2*(x + y)^(1/2)), x, 'Real', true); which gives me the implicit solutions as a function of y. Now try R_c(.3) to find the explicit solution at y = 0.3. MATLAB's answer is: ans = 0.42846617518653978966562924618638 0.15249587894102346284238111155954 0.12068186494007759990714181154349 However, the

Model complex equation in R

二次信任 提交于 2020-01-04 14:09:17
问题 I have the following model: which I've coded in R as: function(t,C,Ao,s,wd,ph) C + Ao * exp(-s*t) * cos(wd*t + ph) I want to use this equation to form a predictive model. However, I can't figure out how to either successfully run or plot this equation. I tried nls but got various errors (including those that warned me about a singular gradient . I looked here but I don't see where to go form here given that my model doesn;t seem to work. How can I model and graph this function in R? What I

Haskell equation solving in the real numbers

岁酱吖の 提交于 2020-01-04 05:29:31
问题 I've just started playing with GHCi. I see that list generators basically solve an equation within a given set: Prelude> [x | x <- [1..20], x^2 == 4] [2] (finds only one root, as expected) Now, why can't I solve equations with results in ℝ, given that the solution is included in the specified range? [x | x <- [0.1,0.2..2.0], x*4 == 2] How can I solve such equations within real numbers set? Edit: Sorry, I meant 0.1 , of course. 回答1: As others have mentioned, this is not an efficient way to

Solving a system of nonlinear equations in R

心已入冬 提交于 2020-01-03 02:21:41
问题 Suppose I have the following system of equations: a * b = 5 sqrt(a * b^2) = 10 How can I solve these equations for a and b in R ? I guess this problem can be stated as an optimisation problem, with the following function... ? fn <- function(a, b) { rate <- a * b shape <- sqrt(a * b^2) return(c(rate, shape) ) } 回答1: In a comment the poster specifically asks about using solve and optim so we show how to solve this (1) by hand, (2) using solve , (3) using optim and (4) a fixed point iteration. 1