I want to plot a function for different values of time

조회 수: 2 (최근 30일)
Anshuman S
Anshuman S 2020년 3월 3일
답변: the cyclist 2020년 3월 3일
This is a function in 2 variable (x,t)
f = (699729515992263*exp(-(3555899736243218994140625*t)/9007199254740992)*cos(20000000*pi*x))/144115188075855872 - (8478402047166467*exp(-(3555899736243218994140625*t)/36028797018963968)*cos(10000000*pi*x))/1152921504606846976 + (4049874448795339*exp(-(3555899736243218994140625*t)/2251799813685248)*cos(40000000*pi*x))/1152921504606846976 - (4758684662903855*exp(-(32003097626188970947265625*t)/36028797018963968)*cos(30000000*pi*x))/1152921504606846976 - (7369322330077077*exp(-(44448746703040240478515625*t)/18014398509481984)*cos(50000000*pi*x))/2305843009213693952 + 1/100 ;
I want to plot the function f(x) for different values of t , for example for x = (0, 1e-6) and for 10 values of t like { 0, 0.001, 0.002, ... 0.01} .
All together in 1 plot. So there may be 10 plots in a single figure.
  댓글 수: 2
darova
darova 2020년 3월 3일
Did you try to use plot?
What problems do you have?
Anshuman S
Anshuman S 2020년 3월 3일
I don't know how to use plot for 2 variables! Do i need to use a for loop?

댓글을 달려면 로그인하십시오.

채택된 답변

the cyclist
the cyclist 2020년 3월 3일
f = @(x,t) (699729515992263*exp(-(3555899736243218994140625*t)/9007199254740992)*cos(20000000*pi*x))/144115188075855872 - (8478402047166467*exp(-(3555899736243218994140625*t)/36028797018963968)*cos(10000000*pi*x))/1152921504606846976 + (4049874448795339*exp(-(3555899736243218994140625*t)/2251799813685248)*cos(40000000*pi*x))/1152921504606846976 - (4758684662903855*exp(-(32003097626188970947265625*t)/36028797018963968)*cos(30000000*pi*x))/1152921504606846976 - (7369322330077077*exp(-(44448746703040240478515625*t)/18014398509481984)*cos(50000000*pi*x))/2305843009213693952 + 1/100 ;
t = linspace(0,0.01,10);
figure
hold on
plot(t,f(0,t))
plot(t,f(1.e6,t))

추가 답변 (1개)

David Hill
David Hill 2020년 3월 3일
Not sure what you are after, but you can try this:
f = @(x,t)(699729515992263*exp(-(3555899736243218994140625*t)/9007199254740992)*cos(20000000*pi*x))/144115188075855872 - (8478402047166467*exp(-(3555899736243218994140625*t)/36028797018963968)*cos(10000000*pi*x))/1152921504606846976 + (4049874448795339*exp(-(3555899736243218994140625*t)/2251799813685248)*cos(40000000*pi*x))/1152921504606846976 - (4758684662903855*exp(-(32003097626188970947265625*t)/36028797018963968)*cos(30000000*pi*x))/1152921504606846976 - (7369322330077077*exp(-(44448746703040240478515625*t)/18014398509481984)*cos(50000000*pi*x))/2305843009213693952 + 1/100 ;
[x,t]=meshgrid(linspace(0,1e-6,10),linspace(0,.01,10));
plot3(x,t,f(x,t));
surf(x,t,f(x,t));

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by