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 次查看(过去 30 天)
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

采纳的回答

Michal
Michal 2022-5-18
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?

更多回答(1 个)

Sam Chak
Sam Chak 2022-5-18
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)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by