cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

vector of functions direct assignment

niacopetti
1-Visitor

vector of functions direct assignment

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.

ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:niacopetti)

Does this help?

Success!

Luc

View solution in original post

16 REPLIES 16

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.

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

LucMeekes
23-Emerald III
(To:niacopetti)

Like this?

Success!
Luc

Luc, let me first thanks for your interest and reply.

I've to clear that i've already coded the function that use vec2str to obtain the integer value;

what i'm missing is that i don't understand why i can't use my func to index,

conversely from what i see in your code.

Sorry if i've not centered  the sense of your reply;

can you open the xcmd file i've posted in this part of thread and

see ?

LucMeekes
23-Emerald III
(To:niacopetti)

The reason you get fails, is because you're using u, which is incompletely defined.

The symbolic processor (using the ->) does not have problems with that, it will give you the symbolic answer if it can. The numeric processor (using the = ) however needs to know the value for each symbol used. So for the symbolic processor your u is OK. The numeric processor of Mathcad sees a u defined as a set of functions uA(v) through uF(v) of which uC(v) through uF(v) are not defined, and in addition v is undefined.

Luc

So, if i need sym calc,and of course i don't have vector all defined  (this is true for sure in my problem)

i'm forced to do a temp passage like:

tmp:=ind("AC")=13.00

and now :     Res_vect          :=findDl(tmp,angle)

                                   tmp

There is no way to "compact" the code can you confirm?

LucMeekes
23-Emerald III
(To:niacopetti)

Yes, I can confirm.

At the bottom, where you try to use 'compact code' it essentially is a numeric definition, and as I explained above u is numerically undefined. So this will not work.

If you make the definition symbolic (by adding a -> to the definition), the symbolic processor starts complaining about the ind("AC") expression that does not result in an integer. See here, this does not work:

and, also

No error, but also no result.

Success!
Luc

LucMeekes
23-Emerald III
(To:LucMeekes)

Correction: it's uB(v) that is undefined, uC(v) is defined:

LucMeekes
23-Emerald III
(To:niacopetti)

Like this?

Succes!

Luc

What am I missing?  See attached.

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.

LucMeekes
23-Emerald III
(To:niacopetti)

Does this help?

Success!

Luc

Your code works well Luc , and it's possibile to skip same row ("automatically" set to "zero" ).

After my post i've thought something  the assignment  "for row" you've shown in firt part of your reply, but after some (failed) attempt i leave the question.

Now seems clear that we'are forced to assign each element of matrix, even skipping some row.

Your is an effective solution and works but, because the "extra work" to assign each single element i'm seriously thinking that, for the sake of clarity in my code and also for an easy usage, i should keep the solution to collect manually the function_of_v_expression in a vector.

In fact i see more easy  writing the entire expression of function (e..g. uA(v):= v1 +v2 +3*v3) that assign each single coeff. in a mtrix place. (i mean : there is more risk in input error).

Of course using your solution maybe implies more time and attention during input phase but for sure it's better in next code, because at that point i can evaluate directly also symbolically the expressions.

So, if in mathcad there isn't the possibility to a "simple assignment"

(i mean something like :

                                   fun_vect(v)    := v1 +v2 -5*v3

                                                   12

)

where the user can write the entire expression  function of v, i prefer continue the use of "manual assignment ".

Can you confirm (for your knowledge of course) that there is not this possibility in mathcad ?

RichardJ
19-Tanzanite
(To:niacopetti)

Does this do what you want?

Werner_E
25-Diamond I
(To:niacopetti)

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

Werner_E
25-Diamond I
(To:Werner_E)

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

Announcements

Top Tags