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

Click For Summary

Discussion Overview

The discussion revolves around creating a simplified and generic code in Mathematica for handling 17 repetitive formulations or expressions that are interconnected. Participants explore ways to condense these expressions into fewer lines of code while maintaining functionality for all variations based on a parameter.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant inquires about simplifying 17 repetitive expressions into a more concise code structure, suggesting the use of a general function like sub[r_].
  • Another participant suggests defining sub[1] = ... instead of using sub1 = ..., indicating that the use of blanks (_) in the definition may not be necessary if the right-hand sides are already defined.
  • A later reply questions whether there is a clear mathematical formulation that generates all the subs, indicating uncertainty about the initial code provided.
  • One participant expresses a desire to create a generic code that computes matrices based on the value of r, seeking further assistance.
  • Another participant proposes implementing a recursive definition, implying that the original poster has a clear idea of what they want to achieve.
  • A participant expresses appreciation for the help received, noting issues with accessing an attached notebook and seeking further clarification on why sub[1] does not return the expected expression.

Areas of Agreement / Disagreement

Participants appear to have differing views on the best approach to simplify the code, with some suggesting specific methods while others seek clarification on the underlying mathematical formulation. The discussion remains unresolved regarding the most effective way to implement the desired functionality.

Contextual Notes

There are indications of missing assumptions regarding the mathematical relationships between the expressions and the specific requirements for the code. The discussion also reflects uncertainty about the effectiveness of the proposed solutions.

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 ·
Replies
6
Views
4K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K