How do I write an exponential function (e^x)? - pascal

I want to be able to pass integer values to a function - e^x and return the result. Based on reccurence relation of e^x. Can someone help me with this?
Thanks in advance.

You don't need to do that. Pascal already has this function: exp(x).

Related

Call the same method but with different arguments, better way

I have something like this in my function with calls the print_hash function three times but with different args. How to do it nicer?
The print_hash function is just only about print key and value.
print_hash(#hash1)
print_hash(#hash2)
print_hash(#hash3)
Thanks in advance
You can try something like:
[#hash1, #hash2, #hash3].each(&method(:print_hash))

Prolog Predicades Relation

I studing prolog and i got issues to resolve this exercise:
I need to create a a method that I call Relation(Variable, List of List)
EX:
list(a,b)
list(c,b)
list(c,h)
Return should be all the list that contains the variable Relation(c,X)
X= [[c,b],[c,h]]
Thank you in advance for your help
Here is the answer to the question :
check(_,[],X).
check(Var,[H|T],[H|X]):-member(Var,H),check(Var,T,X).
check(Var,[_|T],X):-check(Var,T,X).
Only that im not sure how to use the setof/3 procedure , since i need to load the predicates like this
list(a,b)
list(b,c)
list(c,t)

What is wrong with this mat lab code?

This is the problem:
Write a function called top_right that takes two inputs: a matrix N and a scalar non-negative integer n, in that order, where each dimension of N is greater than or equal to n. The function returns the n-by-n square array at the top right corner of N.
My code:
function s=top_right(A,n)
s=A(1:n,end-n+1:end);
I dont know where I am wrong,
Thank you!
from your post and the corresponding commments its fair to assume you are new to MATLAB and stackoverflow. first to your question:
Your code works fine and does what it should, but i think it is somewhere it the script you work in. to use that as a function open a new script copy
function s=top_right(A,n)
s=A(1:n,end-n+1:end);
end
in there and save as 'top_right.m' (the name will be suggested when you save). while you work in that folder you can call your function with top_right(A,n)
Second on how to ask question here so you can get a correct answer quickly. Check https://stackoverflow.com/help/mcve and make your question look like it is described, like:
hey you beautiful people! i am trying to get the top_right function to work, which should return the top right part of a matrix. my code is:
A=[(1:10)'*(1:10)];
function s=top_right(A,n)
s=A(1:n,end-n+1:end);
end;
but leaves me with the error
Error: File: test.m Line: 1 Column: 1
Function definitions are not permitted in this context.
Welcome to stackoverflow!

IDL Integration

I'm looking to integrate a function I am building, but the function would change each iteration based on a given input. For instance:
y=4e^(mx/4)
I would want to integrate with respect to x with a lower and upper bound, but the value of m would change. I know all my values of m.
Can I work with this? My initial assumption would be to use QROMB but that seems limited and unable to handle my issue.
QROMB (and other integrators) want a function of one variable, so you have to get the m in there through the back door. One way is with a common block:
function integrand,x
common int_common,int_m
return,4*exp(int_m*x/4)
end
function integrator,m,xlow,xhigh
common int_common,int_m
int_m=m
return,qromb('integrand',xlow,xhigh)
end
integrator(m,xlow,xhigh) will return the integral you want.

Can the parameter epsfcn be specified in lmfit to approximate the Jacobian?

I want to specify the epsfcn value for the leastsq option in lmfit. Can the epsfcn value be specified?
Let me answer my own question. The keyword argument espfcn can be added to the minimize function and is automatically passed on to the leastsq function. I hadn't seen that in the documentation of the minimize function. It works great.

Resources