Skip to main content
1-Visitor
June 30, 2016
Solved

vector of functions direct assignment

  • June 30, 2016
  • 5 replies
  • 4557 views

Hello,

maybe this is a silly question but i've not found useful results in forum.

I'm looking for create an array of function, something like :

direct_fun_vect(v)1:= v1+ 2*v2 +3*v3

direct_fun_vect(v)2:= v1 - v2

ect..

in a way that mathcad knows that each row is a function of v-vector (v1 , v2 ,v3).

I've found a solution writing the single function like :

f1(v):= v1 + 2*v2 +3*v3

f2(v):= v1 - v2

ect.

and then assigning manually each function to a relative place in a vector like :

manual_fun_vec1:=f1(v)

manual_fun_vec2:=f2(v)

ect.

But in this way i'cant evaluate directly for example the i-esim function in an assigned vector x : ( 4; 1 ; 7) 

Like :   manual_fun_vec1(x) -->

I've to do a temp passage : tmp(v):=manual_fun_vec1 

then i can do :      tmp(x) ->    to obtain result.

I'm searching for a direct assign like :

direct_fun_vec(v)1:= v1 + 2*v2 +3*v3

ect.

so i can evaluate each function in a for cycle like :

for i e 1..N

sum<- sum + direct_fun_vect i (v)

See the attached file to understand well.

Best answer by LucMeekes

Does this help?

Success!

Luc

5 replies

12-Amethyst
June 30, 2016

I don't know a way to do that, and need to do "by hand", as in your example. See for example Re: No name curve . Notice how inneficient is that: Coords are evaluated for the 4 matrix values each time, just for isolate each x1, x2, y1, y2 component.

Best regards.

Alvaro.

1-Visitor
June 30, 2016

Thanks for your experience, i'm so new to mathcad programming.

Maybe someone can suggest some tricks, if possibile.

I take this occasion to ask your another simple question :

why i can't use directly the returned value of function to index a vector :

some_func(x):=| (some stuff with x passed string)

                       |

                       | return res

vector                              := some_var_to_assign;

          some_func("AC")

I need to evaluate some_func and assign to a temp var like :

tmp:=some_func("AC")=13.000

then i can :

vector          := some_var;

          tmp

23-Emerald IV
June 30, 2016
23-Emerald IV
June 30, 2016
23-Emerald I
June 30, 2016

What am I missing?  See attached.

1-Visitor
June 30, 2016

Sorry , you and Luc are right, 'cause i've not explained well the question.

I've writed about f1(v), f2(v) ect. but in my real problem some func may missing.

I mean    i can have func1(v)  --> in first place of vector

                         func3(v)   ---> in third place of vector

                         func7(v)    ---> in 7th place of vector

and not other func. 

I would avoid to specific explicit a "zero" line because my func maybe a lot , so would be useless and time-comsuming write all lines.

In our reply this is a fault because :

in Luc code i've to write for example :

          1       2     3

M:=      0     0     0          ---> second line of zero because i've not any func2

          2     3     1

          0     0     0          --> other zero line

          0     0     0          ---> other zero line ect.

          ect.

This is also a trouble in your solution Fred.

For this i was interested in assignement like when in vector i write in example :   

     v    :=  667

      12 

and this make a 12 length vector of zero in all place except in place 12.

Fred, as a responde to your question in your prop solution i've to explain that, for an exam, i've to obtain a sym result, so i'm forced to done sym evalutation.

I hope you can understand my English.

Thanks in advance for any reply.

LucMeekes23-Emerald IVAnswer
23-Emerald IV
July 1, 2016

Does this help?

Success!

Luc

19-Tanzanite
July 1, 2016

Does this do what you want?

25-Diamond I
July 1, 2016

If I understood the thread correctly so far, your problem/question (or at least one of them) is, that you don't want to add the necessary zeros manually.

Maybe a programmed approach like the following could help:

Regards

Werner

25-Diamond I
July 1, 2016

Here is a better variant as the function vector is called just once in this version: