How to do what MATLAB does with array[index:index] in Maxima? - matlab

I can't figure out how to dynamically take a portion at a time of a column vector in Maxima; for example I have the vector v = [a, b, c, d, e] and I want to take this: [a], [a, b], [a, b, c], etc.
How can you do this in Maxima?

Maxima doesn't have range indexing as in Matlab. A way to get that is to say makelist(A[i], i, i1, i2) where i1 and i2 is the range you want. This is equivalent to A(i1:i2) in Matlab.

Related

Are there limitations with non-zero boundary conditions using ode45 on linearized systems in MATLAB?

First of all, I know the simple answer is yes. I have a few functions and a script that I am calling to try to solve a mechanical model with. I have a function of constants:
function [m1, m2, m3, M, alpha, R, g, l, kys, I3, k1, k2, c1, c2, kr] = variable_constants2()
m1=2500;
m2=1500;
m3=8000;
M=m1+m2+m3;
alpha=pi/8;
R=10;
g=-9.81;
l=2*R*sin(alpha)/alpha;
kys=(1/(72*alpha))*(18*alpha^2+9*alpha*sin(2*alpha)...
-32*sin(alpha)^2);
I3=m3*kys;
k1=1e4;
k2=1e4;
c1=1e4;
c2=1e4;
kr=1e4;
end
I have a function which defines my mass matrix of the system (yes I know that many variables are unused, I am just leaving them there for now):
function M = mass(q)
[m1, m2, m3, M, alpha, R, g, l, kys, I3, k1, k2, c1, c2 kr] = variable_constants2();
M = zeros(6,6);
M(1,1)=1;
M(2,2)=-(2*m3+m1);
M(2,6)=-(2*m3*l*sin(q(5)));
M(3,3)=1;
M(4,4)=-m2;
M(5,5)=1;
M(6,6)=-(2*I3-2*m3*l);
end
I have a function that sets up the state-space model in the form of q_dot = M^-1*q. where q is the matrix of state variables of the system:
function dYdt = f(t,q,P)
[m1, m2, m3, M, alpha, R, g, l, kys, I3, k1, k2, c1, c2 kr] = variable_constants2();
q_matrix=[q(2)
k1*q(1)+k2*(q(3)-q(1))+m1*g+2*m3*g+q(2)*(c1+c2)+q(6)^2*cos(q(5))
q(4)
k2*(q(3)-q(1))+m2*g+q(4)*(c1+c2)
q(6)
2*m3*l*q(6)*q(2)*cos(q(5)) + 2*kr*q(5) + 2*m3*l*(g*sin(q(5)) ...
+q(2)*sin(q(5))*q(6))];
M = mass2(q);
dYdt = M\q_matrix;
end
And finally, there is a script that I am trying to run which calculates the solution to this differential equation set:
[m1, m2, m3, M, alpha, R, g, l, kys, I3, k1, k2, c1, c2, kr] = variable_constants2();
tspan = linspace(0,50,100);
Y0=[-0.564513980920171,-8.788646829574525,-0.567,-4.099961183480138, **0**, **0**];
[t,q] = ode45(#f2,tspan,Y0);
Those two zeros encased in the asterisks should be able to be non-zero and I would like them to be for the model, but the solver fails when trying to change these to a non-zero value. MATLAB seems to be looping infinitely or at least doing something that causes the solver to freeze up. I may have not let it run long enough, but when I am able to just let it run I will and see if I get an error message. If these are zero, the output q is completely fine and I can plot those easily, but otherwise, I run into a problem. Is there a problem with my model described in f2? I have been getting pretty stuck. Thank you.

Creating a matrix with the smallest arrays of some matrixs in matlab

I have some different matrices with equal size, for example, say 5 different N by N matrices A1, A2, A3, A4 and A5. I want to create an N by N matrix B such that B(i, j) is the smallest element among A1(i, j), A2(i, j), A3(i, j), A4(i, j) and A5(i, j).
Since N is a big number, more efficient code is preferred.
As an alternative,
A = cat(3, A1, A2, A3, A4, A5); % store equal-size 2d arrays in 3d array
B = min(A, [], 3); % take minimum in 3rd dimension
Not the most pretty but B = min(min(min(min(A1,A2),A3),A4),A5); should work.

Sugeno Fuzzy Output Coefficients

if input 1 = x and input 2 = y, then output z is equal to ax + by + c.
What do the variables a, b and c correlate to?
Could these be something to do with each rules weight?
How do we calculate a, b and c?
What does that have to do with the data which we have in hand?

Convert data to fuzzy data

I am beginner. I have a matrix in matlab and I want Convert matrix's number to fuzzy number and use these fuzzy number for my function's input .how can I do this?
is it correct to Convert number to double number between 0,1 by Dividing numbers by 1000 like this?
[256,12;3,56]--->[0.256,0.12;0.003,0.056]
but for double number what should I do?
What do you mean by fuzzy number?!! as far as I know MATLAB uses normal numbers for Fuzzy system. After that there are fuzzifiers that change the real numbers to the points on the membership functions. And then the fuzzy logic decides that how the number have to be selected, and so on...!
On the other hand, If you want to change the scale of the number to be in the range [-1 1] or [0 1] then it has nothing to do with fuzzy.
and to change from the range [0 1] to [a b] use this line of code:
r = a + (b-a)*z;
where the z is in the range [0 1], and the r is in the range [a b]
for example, changing z=0.5 from [0 1] to the range [0 10], r becomes:
r = 0 + (10-0)*0.5 = 5
to change from [a b] to [0 1] also you can do this:
z = (r - a)/(b-a);
so if r = 5 in the range [0 10], then z = 0.5 in the range [0 1];
In addition, for the real fuzzy operation, try something like this:
point_n = 101; % Determines MF's resolution
min_x = -20; max_x = 20; % Universe is [min_x, max_x]
x = linspace(min_x, max_x, point_n)';
A = trapmf(x, [-10 -2 1 3]); % Trapezoidal fuzzy set A
B = gaussmf(x, [2 5]); % Gaussian fuzzy set B
C1 = fuzarith(x, A, B, 'sum');
subplot(2,1,1);
plot(x, A, 'b--', x, B, 'm:', x, C1, 'c');
title('fuzzy addition A+B');
C2 = fuzarith(x, A, B, 'sub');
subplot(2,1,2);
plot(x, A, 'b--', x, B, 'm:', x, C2, 'c');
title('fuzzy subtraction A-B');
C3 = fuzarith(x, A, B, 'prod');
That's how you perform fuzzy arithmetic. According to MathWorks:
Using interval arithmetic, C = fuzarith(X, A, B, operator) returns a fuzzy set C as the result of applying the function represented by the string, operator, which performs a binary operation on the sampled convex fuzzy sets A and B. The elements of A and B are derived from convex functions of the sampled universe, X:
A, B, and X are vectors of the same dimension.
operator is one of the following strings: 'sum', 'sub', 'prod', and
'div'.
The returned fuzzy set C is a column vector with the same length as
X.
And Finally you can perform fuzzy inference calculation using 'evalfis' function in MATLAB. The inputs and outputs to this function are real numbers as well:
fismat = readfis('tipper');
out = evalfis([2 1; 4 9],fismat)
This syntax generates the response
out =
7.0169
19.6810

Splitting matrix into columns

I ve got a matrix and i want to split is in the columns vectors. I want to have as output the
above vectors [a b c d e f g h k l m n o p q r s t u] and as an input the matrix A. is there any idea?
You can do this by converting your matrix to a cell array as follows:
M = rand(4); % create a 4x4 random example matrix
C = num2cell(M,1); % convert every column to a cell
[a,b,c,d] = deal(C{:}); % assign to variables a...d
This results in four column vectors a, b, c, d. Add more letters as needed.
I'm not really sure why you would want to do this though, I think it's probably more efficient to just index your original matrix with the column number you need.