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 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Thomas TJOCK-MBAGA
il 18 Mag 2022
Commentato: Thomas TJOCK-MBAGA
il 18 Mag 2022
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
0 Commenti
Risposta accettata
Michal
il 18 Mag 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?
Più risposte (1)
Sam Chak
il 18 Mag 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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1001975/image.png)
2 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements 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!