Effacer les filtres
Effacer les filtres

Hello everyone please I have a problem. How to declare a function with two variables in MATLAB and plot the evolution according to one variable after having fixed the other ??

1 vue (au cours des 30 derniers jours)
Hello everyone please I have a problem. How to declare a function with two variables in MATLAB and plot the evolution according to one variable after having fixed the other ??? For example I declare y = exp (-0.1xt + x) x sin (3x) after first declaring the variables x and t, I would like to plot the evolution of y as a function of x for t = 1, 2 and 3. Thank you Best regards !!!
I Wrote the following code
clear aller Close all x = linspace (0, 1, 25) t= linspace (0, 5, 500) y= exp (-0.1xt + x) x sin (3x) plot (x, c(1,:), 'bo', x,c(2,:), 'mo', x, c(3,:), 'co')
When on run the code the message issu Matrix dimension must agree

Réponse acceptée

Michal
Michal le 18 Mai 2022
Also, due to Matlab's explicit matrix expansion (I think that's waht they call it), you can simply use the dimensions to cereate your vectors for the different t values, like this:
x = 1:100;
t = [15;20;25]; % a different dimension from x
y = exp(-0.1*x.*t+x).*x*3.*sin(x); % each row of y is y=f(x) for the corresponding t
plot(y');
Is this what you were after?

Plus de réponses (1)

Sam Chak
Sam Chak le 18 Mai 2022
Because one is 1x25, and the other is 1x500. Now both are 1x100.
x = linspace(0, 1, 100);
t = linspace(0, 5, 100);
y = exp(-0.1*x.*t + x).*x.*sin(3*x);
plot(x, y)

Produits


Version

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by