How can I plot graph using external function?
7 views (last 30 days)
Show older comments
Sojung Park on 12 Mar 2023
I am trying to plot this equation.
I have the values of B, omega_d, zeta, N_k and t_j is the multiples of 1.89.
First, I tried make an external function to represent the equation including sigma and deduce a function about t. Then tried to draw a gragh for t in conclution.
But I am struggling with where to define t_j, call the external function, and making a function about t and plotting it. It's the code that I wrote below.(there will be lots of errors but don't know how to fix it..)
Any comment will be helpfull. Please help, thanks!
function [sum]= s(t)
sum= sum+ exp(-(zeta/2).*(t-t_j)).*(-zeta*(sin(omega_d/2.*(t-t_j)))+ omega_d.*cos(omega_d/2*(t-t_j)));
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable. I also swapped the order of the two code sections so it can be run directly in this forum.
If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks).
In this case the first thing to fix is your usage of sum as a variable name. You really should avoid function names when picking a variable name. If you use sum later on, will you remember that you made it a variable instead of the function?
The next thing is to add an initial value to your output, which we will make 0.
Lastly, when using fplot you need to provide a function handle. You called the function directly instead. You also didn't use any of the previously calculated values. Below I show two ways to plot this function, along with the other corrections to your code.
plot(t,sum_value) % you can increase level of detail with t=linspace(0,10,50);
function sum_value= s(t)
% Write an explanation of this function here, along with example usage.
sum_value= sum_value+ exp(-(zeta/2).*(t-t_j)).*(-zeta*(sin(omega_d/2.*(t-t_j)))+ omega_d.*cos(omega_d/2*(t-t_j)));
More Answers (0)
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!