How to plot this function?
    7 ビュー (過去 30 日間)
  
       古いコメントを表示
    
I have a function that is "vectorized". I did that because I wanted to have one such function for each value of the parameter "a":
clc;
clear all;
tic;
a=[1/2,1/3,1/4];
p = @(x) 1/3.*(exp(x.^(a))-1)./(exp(x.^(a))+1) ;
I want to have the three plots (one for each value of "a") in the same figure. However, I am having trouble isolating each function for plotting. For instance, I expected that:
p1 = @(x) p(x,1,1)
would represent one of functions, but it doesn't. My other attempts have also failed. How can I get the desired result?
0 件のコメント
採用された回答
  Star Strider
      
      
 2014 年 12 月 24 日
        
      編集済み: Star Strider
      
      
 2014 年 12 月 24 日
  
      The easiest way is to pass ‘a’ as a parameter as well:
a=[1/2,1/3,1/4];
p = @(x,a) 1/3.*(exp(x.^(a))-1)./(exp(x.^(a))+1) ;
p1 = p(x,a(1));
Not that within the function, ‘a’ is whatever you want it to be. If you define it as a parameter, it will not pick up the value of ‘a’ from the workspace.
4 件のコメント
  Star Strider
      
      
 2014 年 12 月 24 日
				Thank you. I do my best!
Now I understand what you’re doing. If you only want it as a function of ‘x’, you have to specify it as you did:
p1 = @(x) p(x,a(1));
It all depends on how you want to call your function. There are at least a few ways to do it correctly, so choose the one that works best for you in your application. I chose the way I usually do it in my two versions of the plot call.
その他の回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Axes Appearance についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!