I am working on a project in MATLAB that is essentially a linear system solver for a physical problem with lots of parameters and this is my first time trying OOP. Before, I had lots of MATLAB scripts with lots of very similar code so I thought this would be a good example to learn OOP with.
I have a class with properties that contain all the parameters that could be present in the physical problem (but not necessarily all of them could be needed), and the size of the linear system I want to use to solve it. I have two dependent properties that represent the matrix A and the right-hand side vector B. Solving Ax = B is the whole point of the application.
I am now trying to write a get method to determine B. My problem is that this does not follow a formula that can be expressed generally in terms of the class properties. (It can, but in different ways for each problem. What I mean is, for one problem can have a dependence like B(n) = obj.parameter1*obj.parameter2 and for another it can have B(n) = 3*obj.paramter(1)*obj.parameter2)
I am wondering if the above points to having to define B outside of the class? If so, how can I avoid being in the same situation that I was before, having lots of similar scripts defining B?
The one thing that will always be consistent across problems is that B is defined algebraically in the following way:
nj = -10:10 % array of integers from -10 to 10
for m=1:length(nj)
if nj(m) == 0
B(m) = % (function)
else
B(m) = % (another function, dependent on m)
end
end
I hope this makes sense. Thank you for helping out this clueless mathematician.
Silver Pages is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.