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)
참고 항목
카테고리
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!