How to write in Matlab a matrix whose coefficients depend on a real alpha parameter
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Djamel
il 26 Mar 2024
Commentato: Djamel
il 2 Apr 2024 alle 14:33
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 Commenti
Risposta accettata
John D'Errico
il 26 Mar 2024
Modificato: John D'Errico
il 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)
Più risposte (1)
Voss
il 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 Commenti
Vedere anche
Categorie
Scopri di più su Line Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!