Mathematica How to make a simplified general code for repetitive formulations in Mathematica

AI Thread Summary
The discussion revolves around simplifying 17 repetitive mathematical formulations into a more concise code structure. The user seeks a way to express these formulations using a general code, specifically in the form of sub[r_]:= ..., which would allow substitution for values of r from 1 to 17. Suggestions include defining sub[1] = ... instead of using separate variables for each expression. A recursive definition is proposed as a potential solution, although the user struggles with the implementation. There are issues with sub[1] not returning the expected expression, and the user requests a notebook containing the necessary code, expressing gratitude for the assistance received.
kaizen.moto
Messages
94
Reaction score
0
Hi there,

I have altogether 17 formulations or expressions which are repetitive and have link from each other.

My question is that how to make these formulation or expressions in a simpler form. In another word, how to make the codes or syntax become shorter due to these repetitive expressions.

Is there any better way to express all the 17 formulations in just one or two general codes but yet it works for all 17 expressions.

For instance:

the general expression is sub[r_]:=..... (1)

so if I want to substitute the value of any r, from 1 to 17, I got all the different 17 expressions as stated in the notebook attached.

Thank you in advance for any feedback.
 

Attachments

Physics news on Phys.org
Of course you can define
sub[1] = ...
instead of
sub1 = ...
and so on. If you're happy to use the current right-hand-sides of the definitions.
You don't need to have blanks (_) in the definition, i.e. you don't need sub[r_] := ...

But if you want to generate the right-hand-sides of the definition and use a single
sub[r_] := something goes here that depends on r
Then that might be a bit trickier. Do you have a clear mathematical formulation that generates all of the subs? I couldn't see anything too obvious from your code.
 
Sorry, I think I have confused you.

Actually, Iam trying to create a generic code of which I think looks like this sub[r_]:= ...

This desired generic code would be applicable to compute all the matrices as per r value.

Please see the revised notebook.

Thank you for any help.
 

Attachments

OK, you can implement a recursive definition.
Your text showed that you knew what you wanted, just not how to obtain it!

See the attached notebook.
 

Attachments

wow..brilliant!. Eventhough, the notebook you sent was empty, I could not manage to open it. But, I have re typed the syntax from the pdf file and run the codes, its really works...you are truly very good at this...fantastic job..and I become more and more like Mathematica itself.

For your info, why sub[1] does not return the required expression. I mean when I run sub[1], it gives me sub[1]. However, the rests are working perfectly.

anway, can you please send the notebook again to my email add at kaizen.moto@yahoo.com, if you don't mind.

I really really apreciate your kind help..may God bless you..
 

Similar threads

Replies
6
Views
4K
Replies
1
Views
2K
Replies
4
Views
3K
Replies
22
Views
3K
Replies
3
Views
2K
Replies
1
Views
2K
Replies
1
Views
6K
Back
Top