Resizing Matrix

Resizing Matrix - Copy / Paste Matrix - How to Resize - Сообщения

#1 Опубликовано: 08.05.2014 17:23:34
Ryan Freund

Ryan Freund

19 сообщений из 339 понравились пользователям.

Группа: User

I would like to use multiple instances of a calculation. However the size of the matrix must be resized depending on the input parameters. The problem I'm having is when the matrix needs to be smaller the data from the previously defined (larger) matrix is used.
Is a solution here?

See attached example.

Thank you!!
Beam - Uniform - Multiple Beam.sm (18 КиБ) скачан 54 раз(а).
#2 Опубликовано: 08.05.2014 17:47:10
Davide Carpi

Davide Carpi

1415 сообщений из 2872 понравились пользователям.

Группа: Moderator

As general rule of any programming language, when you start a new task on the same environment you must unset all the variables that you want to overwrite; use Clear(b.trib,w.DL,w.LL,...) or b.trib:mat(0,1,1) ... w.DL:mat(0,1,1) ... etc to do the task;
However when you have repetitive tasks the best way is to build a couple of functions with input argument LG and output argument a vector or a system containing the loads and the moments (this is safe and there's no needs to unset something).


Best regards,

Davide
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#3 Опубликовано: 08.05.2014 17:50:21
Ryan Freund

Ryan Freund

19 сообщений из 339 понравились пользователям.

Группа: User

Thank you very much. I figured they needed to be cleared but could not remember how.

Цитата

Otherwise the best way is to build a couple of functions with input argument LG and output argument a vector or a system containing the loads and the moments.



I'm not sure what you mean by this. What is a "system" containing the loads and moments?

Thanks again
#4 Опубликовано: 08.05.2014 18:05:23
Davide Carpi

Davide Carpi

1415 сообщений из 2872 понравились пользователям.

Группа: Moderator

You're welcome

Wrote

I'm not sure what you mean by this. What is a "system" containing the loads and moments?


Something like this in the attachment


Beam - Uniform - Multiple Beam.sm (40 КиБ) скачан 91 раз(а).
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#5 Опубликовано: 08.05.2014 18:21:19
Ryan Freund

Ryan Freund

19 сообщений из 339 понравились пользователям.

Группа: User

Wow, thank you! (my thank button does not seem to work).

So bascially you defined a function, loads(). I should make a point to remeber that this is a function not a matrix therefor you must define a matrix also named loads = loads(LG). This is required because you cannot call for values contained in the loads(LG) function.
However now that I have this function I can reuse it throughout the page. Very nice.

questions:
What is the "#" symbol for?
What is the systems symbol for, meaning what does it do? It just inputs vectors into a matrix?

thanks again

#6 Опубликовано: 08.05.2014 18:48:26
Davide Carpi

Davide Carpi

1415 сообщений из 2872 понравились пользователям.

Группа: Moderator

Wrote

questions:
What is the "#" symbol for?
What is the systems symbol for, meaning what does it do? It just inputs vectors into a matrix?



I use #var for "local" variables, so any other variable is "global" (loads is not only function of LG, also of LF.DL etc...); I strongly suggest to use some trick like this, for a fast and easy debug/maintenance (you can use #var _var `var Var VAR or whatever is the best way for you... to add the # symbol before the word, write the word and then move the text cursor to the first character and place the symbol)

About functions remember these rules:
- any variable created inside the function is 'local';
- you can get variables from outside the function, if doesn't exists inside the function;
- if you define a new value for an input argument, this is global (affects the input variable outside the function) (this is called "passing by reference", if I remember correctly the official name of this feature)

In your worksheet, when you define [math eng]el(b.trib,1)[/math] inside the function, SMath as first thing attempts to replace the first matrix element; because doesn't exist yet as local variable, Smath looks in the worksheet for a global variable: if exist will be used as base inside the loop (and here you are back to the issue of the first post), otherwise initialize an empty matrix. Using a name "hardly utilizzable on the canvas", you skip any issue.

As you can see copying a not filled function from SMath to a text editor, # is used as empty placeholder; this is why you can't write directly a variable using # as first character


Best regards,

Davide


P.S. the dynamic assistance show you that loads is a function; however you can set a description text to point out this fact.
2014-05-09 01_05_07-SMath Studio Desktop - [Beam - Uniform - Multiple Beam.sm_].png
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#7 Опубликовано: 08.05.2014 22:17:06
Ryan Freund

Ryan Freund

19 сообщений из 339 понравились пользователям.

Группа: User

Excellent explanation, thank you!
#8 Опубликовано: 12.05.2014 11:01:56
Ryan Freund

Ryan Freund

19 сообщений из 339 понравились пользователям.

Группа: User

I'm wondering if I could apply the concept of functions to 'function' as "engine pages" see here and here

Basically I have a bunch of different input that I can send to the function multiple times on a page. hmmmm....

#9 Опубликовано: 12.05.2014 16:35:21
Martin Kraska

Martin Kraska

1222 сообщений из 2150 понравились пользователям.

Группа: Moderator

Wrote

I'm wondering if I could apply the concept of functions to 'function' as "engine pages" ...

Basically I have a bunch of different input that I can send to the function multiple times on a page. hmmmm....



This would work. The disadvantage is that you cannot use ordinary SMath sheets as function descriptions. Instead, you have to write sort of
program (using the line() operator) to do the job.

Before designing the functions you perhaps might consider to define
- the problem data structure and methods to apply to this data structure
- methods data structure like tables, only accessed within the methods

Both structures can be just global variables or single complex objects. You can fake objects with named attributes by using a 2-column matrix with name strings in the first column and whatever object in the second column and define a corresponding set(structure,name,value) and get(structure,name) function pair.

Functions can provide return values and can modify arguments, if these are given as names (call by reference). They cannot modify global variables (any assignment to a name which does not occure in the formal parameters list creates a local variable, shadowing global objects of the same name).
setget.PNG
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
2 пользователям понравился этот пост
ioan92 13.05.2014 02:55:00, sergio 13.05.2014 03:26:00
#10 Опубликовано: 13.05.2014 15:50:46
Ryan Freund

Ryan Freund

19 сообщений из 339 понравились пользователям.

Группа: User

Thanks for the further comments.

One quick question -

I tried to update my previous post to include moments but seem to be struggling to do so.
I've attached the calculation and hope you can make sense of it. I'm not sure why I'm receive these errors.

Also what is the output window for?

Thanks again!
Creating functions Beam - Uniform - Multiple Beam.sm (48 КиБ) скачан 40 раз(а).
#11 Опубликовано: 13.05.2014 16:32:33
Martin Kraska

Martin Kraska

1222 сообщений из 2150 понравились пользователям.

Группа: Moderator

Wrote

Thanks for the further comments.

One quick question -

I tried to update my previous post to include moments but seem to be struggling to do so.
I've attached the calculation and hope you can make sense of it. I'm not sure why I'm receive these errors.

Also what is the output window for?

Thanks again!


The problem is in the mismatch between data structure and indexing. You have a vector of row matrices and try to access the elements just as in a matrix. You have to use nested index levels.

The output window displays the output of trace(), a function for debugging, explained in the wiki
output.PNG
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#12 Опубликовано: 14.05.2014 14:43:06
Ryan Freund

Ryan Freund

19 сообщений из 339 понравились пользователям.

Группа: User

I see what you're saying (I think)... so what I call LoadsM is not a matrix, it is actually a vector ("vector of row matrices").
So how should I handle this? I suppose I could adjust the Moments () function so that I send the individual row matrices to the function (i.e. Moments(#w.tot, #L.b, #R))
Or is there another way I can extract the individual row matrices from the LoadsM vector?

Possibly ->
first step through the number of columns of the vector (which is 1) then step through the number of columns of the row matrices?

Thanks again!!
#13 Опубликовано: 14.05.2014 18:38:48
Martin Kraska

Martin Kraska

1222 сообщений из 2150 понравились пользователям.

Группа: Moderator

Wrote

I see what you're saying (I think)... so what I call LoadsM is not a matrix, it is actually a vector ("vector of row matrices").


To be precise, it is defined as a list (system) of row vectors. Here is a comparison of lists and column vectors:

properties they have in common:
- linear (1D) array of arbitrary objects
- access to elements via index function el()
Lists
- are marked by a left curly brace with the elements aligned left
- functions rows() or length() do not work, there is no way to determine the number of elements except converting to a vector via sys2mat() and then applying the
- can be used instead of scalars in expressions. If multiple lists occure within an expression, then all combinations of elements are used and a corresponding list is returned.
- are more convenient to type (just type sys TAB ).
column vectors:
- are marked with a pair of parens and the elements centered.
- are less convenient to type (use Ctrl-M, adjust numbers of cols and rows or type mat( and resize using the mouse).
- can be used as iterators for loops
- can be operator of matrix multiplication or scalar product

There is much more on lists and matrices in the chapter Mathematics in the interactive handbook. Before making
program structure decisions, you might consider making yourself familiar with the available functions.

The screenshot in my previous post shows how to access the elements.
el(loadsM,j) extracts the j-th element (a row vector) of the list
el(el(loadsM,j),k) extracts the k-th element (a number) of the j-th element.

For iteration over all elements, vectors and matrices are better suited than lists. First, you easily can determine their size, second, you even might use them directly as range in the for statement.

Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#14 Опубликовано: 15.05.2014 09:08:13
Ryan Freund

Ryan Freund

19 сообщений из 339 понравились пользователям.

Группа: User

Thanks for the response and explination. I seem to have an error when trying to replicate. "Argument doesn't match to expected kind"

Error in Accessing System

#15 Опубликовано: 15.05.2014 11:10:03
Ryan Freund

Ryan Freund

19 сообщений из 339 понравились пользователям.

Группа: User

Very interesting -> my problem was that if you type:

loadsM[1[1
Then you receive an error

if you type:
loadsM[1spacebar[spacebar
Then I receive the correct result


So for this problem what is the best way to set up the calculation?

1. Use systems. When I setup my range I can transform the system into a matrix. Then I can access the elements as noted above my Martin.

2. in the loads() function I don't put values into a system. Instead I put them back into a matrix. More work but possibly worth the effort. Maybe there is anothway. I will have to play with it some.
#16 Опубликовано: 15.05.2014 11:38:37
Ryan Freund

Ryan Freund

19 сообщений из 339 понравились пользователям.

Группа: User

One other question.

When creating functions, instead of return a system (like we did above), how would you return a matrix?

Sorry for all the questions. Thanks.
#17 Опубликовано: 15.05.2014 11:57:38
Ryan Freund

Ryan Freund

19 сообщений из 339 понравились пользователям.

Группа: User

Here is an updated calc show some different options, for anyone else who comes across this.

There is one interesting error however which is that it returns one of the matrices as undefined (see attached).

Thanks!
Creating functions Beam - Uniform - Multiple Beam.sm (72 КиБ) скачан 39 раз(а).
#18 Опубликовано: 15.05.2014 12:36:23
Martin Kraska

Martin Kraska

1222 сообщений из 2150 понравились пользователям.

Группа: Moderator

Wrote

There is one interesting error however which is that it returns one of the matrices as undefined (see attached).
Thanks!



You are victim of bug SS-40. Andrey has marked it as fixed but did not yet roll out the fixed version.

You can identify such problems by setting the cursor on some name and watching if all occurences of that name are highlighted in the expression. If not, then there might be a typo or a hidden empty text index.

See the marked spot in the attachment and compare this to your original file.

Edit: The useless error message is just another known bug...
index.PNG
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений