A simple example of what I am doing is as follows:
s := t*0.2:
b := matrix([0.5,0.6,0.1]):
f := matrix([sin(s),cos(s),s]):
X := transpose(b)*(f);
plotfunc2d(X,t=-2*PI..2*PI);
The error is:
Error: Expecting an arithmetical expression or a function. Got a 'Dom::Matrix()' for attribute 'Function' in the 'Function2d' object.
so, I need to convert types from Dom::Matrix to Function. I have tried:
coerce(X,DOM_EXPR);
I know that simply, this works:
s := t*0.2:
x := 0.5*sin(s)+0.6*cos(s)+0.1*s;
plotfunc2d(x,t=-2*PI..2*PI);
Is there a way to convert these types?
While the variable X itself is a DOM::Matrix(), the single element it contains is an arithmetical expression, so you need to pass the element itself to the plot function:
plotfunc2d(X[1],t=-2*PI..2*PI);
Related
I am creating an MSetList P with elements of type String, and I would like to obtain the Powerset of P. I am not being able to figure it out.
Code below.
Thanks for your help :-)
Require Import
Coq.MSets.MSetList
Coq.Strings.String
Coq.Structures.OrdersEx.
Module set := Make OrdersEx.String_as_OT.
Definition P := set.add "A"%string (set.add "B"%string (set.add "C"%string (set.add "D"%string set.empty))).
Compute P.
Answer was provided on the Coq Discourse Forum by Yves Bertot
The construction of set shows that you are using the Make function
with a module as argument. If you type Print Make., you see that
this is a functor taking a module of type OrderedType as argument,
and it produces a module with many fields, among which t, eq,
eq_equiv, lt, lt_strorder, lt_compat, compare,
compare_spec, and eq_dec. If you type Print OrderedType., you
see that these field are the ones required to make an OrderedType.
So Make constructs all the fields that would be required to call Make
again, thus producing the powerset.
You can just type :
Module pset := Make set.
and you will simply obtain a structure of sets, whose elements are in
set.t. The following example was tested with coq 8.15.
Require Import
Coq.MSets.MSetList
Coq.Strings.String
Coq.Structures.OrdersEx.
Module set := Make OrdersEx.String_as_OT.
Module pset := Make set.
Definition set1 := set.add "A"%string set.empty.
Definition set2 := set.add "B"%string set.empty.
Definition set3 := set.add "C"%string set1.
Definition pset1 := pset.add set1 (pset.add set2 pset.empty).
Compute pset.mem set3 pset1.
Compute pset.mem set2 pset1.
I would like to print the function definition of any nested function when printing the definition of the outer function. Example:
g:{sin x}
f:{cos g x}
When I print f I get {cos g x} but I want to get {cos {sin x} x}
Thanks for the help
From what I am aware it is not possible to achieve that with in-build functions.
You can attempt to write your own function that does that but it will be a pain in the end. Something like this maybe:
q)m:string[v]!string value each v:value[f][3] except `
which creates a dictionary m :
q)m
,"g"| "{sin x}"
When given a function value returns a list containing (bytecode;parameters;locals(context;globals);constants[0];...;constants[n];definition)
However, if we pass a symbol to value it returns the value of that symbol (or function definition in this case).
You can then use ssr to replace the functions in f with the function definitions stored in your dictionary m.
q)ssr/[last value[f];key m;value m]
"{cos {sin x} x}"
but to ensure that your function is stable and adaptable to different functions would be very difficult.
For more details about how value have a look here: https://code.kx.com/q/ref/metadata/#value
For ssr check this link:
https://code.kx.com/q/ref/strings/#ssr
I know I can write
a := Object()
a[1] := "textA"
a[2] := "textB"
a[3] := "textC"
Can I write something like
a := {"textA", "textB", "textC"}
?
You can define an indexed array using the bracket syntax:
a := ["textA", "textB", "textC"]
or the array creation function:
a := Array{"textA", "textB", "textC"}
An indexed array is an object representing a list of items, numbered 1 and up. In this example, the value "textA" is stored in object key 1, the value "textB" in object key 2 and the value "textC" in object key 3.
https://autohotkey.com/docs/Tutorial.htm#s7
I'm trying to use Newton's method to approximate where the gradient of a function = 0 But I'm guessing error messages when I try to put in guesses for an iteration of Newton's, and I don't know what the problem is.
(For reference, Profit = 144TVa - 0.07TVb TVb - 0.01 TVa^2 + 174TVb -0.01TVb^2 - 4E5)
with(LinearAlgebra):
with(VectorCalculus):
DProfit := Gradient(Profit, [TVa, TVb])
F := unapply(DProfit, TVa, TVb)
J := Jacobian(DProfit)
Guess := V->evalf(V-Multiply(Jinv,F(V))):
But when I try to evaluate Guess at any points, it gives me an error:
Guess(3000,3000)
Error, (in Guess) invalid input: F uses a 2nd argument, TVb, which is missing
Guess(<3000,3000>
Error, (in Guess) invalid input: F uses a 2nd argument, TVb, which is missing
even though F(3000,3000) returns [-66,-36]
Thanks for the help.
Figured out how to fix it!
Instead of:
Guess := V->evalf(V-Multiply(Jinv,F(V))):
I did:
Guess := V->evalf(V-Multiply(Jinv,F(V[1],V[2]))):
I am encountering a problem when manipulating sequence element in Maple. First of all, here is the code.
b[0] := t -> (1-t)^3;
b[1] := t -> 3*t*(1-t)^2;
b[2] := t -> 3*t^2*(1-t);
b[3] := t -> t^3;
P := seq([seq([j*(i+1), j*(i-1)], i = 1 .. 4)], j = 1 .. 3);
EvalGamma := proc (b, P, i, t)
local CP, res;
option trace;
CP := P[i];
res := CP[1]*b[0](t)+CP[2]*b[1](t)+CP[3]*b[2](t)+CP[4]*b[3](t);
RETURN res;
end proc;
The variable P is a sequence of sequence : P[i] is a sequence of four 2D points.
But the affectation CP := P[i]; doesn't do what I want : I don't know why but the result is not P[i] in the procedure.
And the weird thing is that, outside the procedure, the following lines work :
CP := P[1];
CP[1];
I would appreciate any suggestions. Thanks.
I'm assuming you call the procedure as
EvalGamma(b,P,i,t)
The problem you are having is that when P is inserted into the sequence of arguments, the nested sequence of arguments is "flattened" to produce the final argument list. An easy way to fix this is to place the sequence for P inside a list structure. So use
P := [seq([seq([j*(i+1), j*(i-1)], i = 1 .. 4)], j = 1 .. 3)];
Once you do that, I think everything will work as expected.
When you call EvalGamma you cannot pass that global P which is an expression sequence of (three) lists (or lists). If you try and do so then EvalGamma will receive 6 arguments instead of 4 as you intend, because each of the three lists (of lists) in expression sequence P gets interpreted as a separate argument of the call.
Instead, you could create P as a list, ie,
P := [seq([seq([j*(i+1), j*(i-1)], i = 1 .. 4)], j = 1 .. 3)];
or you could pass it like EavlGamma(b, [P], some_i, some_name). But you should only do one of those two choices.
Note that the return syntax should be either return res; or (deprecated) RETURN(res);.