I defined the following two functions:
function [z]=f(x,y)
z = x + y - 8
endfunction
function [z]=g(x,y)
z = 2*x + y - 8
endfunction
I then wanted to find the roots of the two functions (equations). That is, I want a pair of numbers (a,b)
such that f(a,b) = g(a,b) = 0. So, I found the function fsolve in the documentation of Scilab which I believe will do what I want. So, I ran the following command:
fsolve([0;0],f,g)
and it produced the following error:
Undefined variable: y
at line 2 of function f called by :
fsolve([0;0],f,g)
I do not understand this error and I am hoping that somebody can tell me what I am doing wrong.
Bob
function c=f(xy),x=xy(1);y=xy(2);c=[(x+y-8);(2*x+y-8)];endfunction
fsolve([0;0],f)
Related
Related to a previous question: I am using Julia Symbolics package and would like to represent 5*pi symbolically. I tried the following to no avail:
using Symbolics
5 * Symbolics.pi # expanded to 15.707963267948966
Num(5) * Symbolics.pi # expanded to 15.707963267948966
#variables x
Symbolics.pi * x # Gives πx, so it works with variables
Desired result, a symbolic expression using Symbolics.pi and the constant that are not numerically calculated on the spot but are kept as a product of 5 and π and show up as 5π, using Symbolics.pi.
Try:
x = Symbolics.pi * Num(5)
print(x)
Here x should be evaluated, hence pi should be promoted.
I have a simple formula for which I want to solve. Assuming all variables other than x are known, I am trying to solve for x by the following folmula: x = [(c-a)/a]^(1/b)
The initial equation was: a * x^b - a = c, and that was my way for solving for x.
Below is a snippet of my code.
a = 5000
b = 5
c = 562
x = ((c-a)/a)**(1/b)
But for some reason it cannot handle it. Any suggestions?
I think the correct formula is:
x = ((c+a)/a)**(1/b)
clf
clc
function dx=f(t,x)
dx(1) = x(2)
dx(2) = -B*(1-x^2)*x(2)-w*w*x(1)
endfunction
B = 5
w = 1
x0 = [10;100]
t = 0:0.01:10
x = ode(x0,0,t,f)
plot2d(t,x)
Now it shows the following problem in scilab console...
at line 3 of function f ( /Users/mottelet/so.sce line 7 )
in builtin ode
at line 15 of executed file /Users/mottelet/so.sce
Submatrix incorrectly defined.
ode: An error occurred in 'lsoda' subroutine.
Please tell me what did I do wrong and tell the solution.
You have a problem in the code of function f at this line
dx(2) = -B*(1-x^2)*x(2)-w*w*x(1)
because the expression -B*(1-x^2)*x(2) yields a vector and you try to assign it to a scalar container (here dx(2)). Maybe you wanted to write -B*(1-x(1)^2)*x(2) or -B*(1-x(2)^2)*x(2) (i.e. replace the first occurence of x by one of its components) ?
I found out about how to increase or decrease a pixel's contrast, and my teacher answered me I could use this formula : R = r*coefficient ; G = g*coefficient ; B = b*coefficient where R, G and B are the contrasted pixel, and r, g, b its old values. The coefficient is a positive or negative percentage choosed by the final-user of my retouching program.
But this formula doesn't work. I searched on the Internet why and I found I must change this formula using for example the sigmoid function.
So my question is : is the formula I wrote below correct ? I don't think so because I did some tests : it doesn't work and I don't understand why.
R = 1/(1 + Math.exp(-(r + coefficient*r)))
NB : it would be fine if I could restrain the images of my function to : [0-255] and the abscissas to [0 - 255] but I don't know how.
I have a function f(x) that gives me results in time domain. I want to get the z-transform of that function so that I can compare both. I know this would be easy to calculate in MATLAB. However, I'm wondering if there is a way to do it in R by a package or writing a code from scratch. The reason for using R because I have done most of the required work and other calculations in R.(Plus R is free)
I searched and found some suggestions to use scale. However, I think it has to do with data not the function. Also, I found a package GeneNet which has a function called z-transform. However, it gives a vector of numbers. I want to get the z-transform as function of z.
By definition z-transform calculated from :
Update for simplicity:
if we have f(x)= x, where x= 0,1,2,3,4,....100. I want to get the z-transform for the given function f(x).
Based on the above definition of z-transform and by substitution:
x(z) = SUM from n=0 to n=100 of (Xn) *(Z ^-n)
for n=0 => x(z)= (0) (Z^-0)
for n=1 => x(z)= 0 + (1) (z^-1)
for n=2 => x(z)= 0 + (1) (z^-1) + (2) (z^-2)
...
..
Any suggestions?
Seems like you've got two problems: calculating f(x) = x XOR 16, and then computing the z-transform of the result.
Here's an (updated) z-transform function which will work on a defined x optionally an arbitrary n vector (with the default assumption that n starts at 0 and goes up by one for each value of x). It now returns a function that can be used to evaluate various z values:
ztransform = function(x, n = seq_along(x) - 1) {
function(z) sum(x * z ^ -n)
}
my_z_trans = ztransform(x = 0:100, n = 0:100)
my_z_trans(z = 1)
# [1] 5050
my_z_trans(z = 2)
# [1] 2
my_z_trans(z = 3)
# [1] 0.75