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
0 件のコメント
採用された回答
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
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1001975/image.png)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!