How to write in Matlab a matrix whose coefficients depend on a real alpha parameter
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
A(i,j) = (1+alpha*x(i)*y(j))*exp(x(i)*y(j))
where almpha is a real parameter, x(i) and y(j) points in [0 , 1] with i , j = 1, ..., N
0 commentaires
Réponse acceptée
John D'Errico
le 26 Mar 2024
Modifié(e) : John D'Errico
le 26 Mar 2024
Many ways. It seems unclear exactly what is your goal. And what are x and y? Are they just a list of numbers? Or a sequence as linspace would provide?
For example, you might do this:
N = 4;
x = linspace(0,1,N);
y = linspace(0,1,N);
syms alpha
A = (1+alpha*x.'*y)*exp(x.'*y)
vpa(A,5)
Of course, x and y might be just any arbitrary vectors of numbers.
Another approach would be to write it as a function handle. This time I'll use random vectors for x and y.
x = sort(rand(1,N))
y = sort(rand(1,N))
Afun = @(alph) (1+alph*x.'*y)*exp(x.'*y);
And now we can evaluate Afun for any value of the parameter.
Afun(0.3)
Plus de réponses (1)
Voss
le 26 Mar 2024
Here's an example:
alpha = 0.4;
N = 9;
x = linspace(0,1,N);
y = linspace(0,1,N);
xy = x(:).*y(:).' % column x * row y
A = (1+alpha.*xy).*exp(xy)
0 commentaires
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!