Attached (in the images) are the problem, and what the graph is supposed to look like. Here is my code:
% Given Values
C= 15 *(10^-6);
Vm= 24;
L= 240 * 10^-3;
R=[10:1:40];
f=linspace(60,110,31);
w= 2*pi*f;
% Given functions
Top= Vm;
Bottom=sqrt((R.^2)+(w*L-(1./(w.*C))).^2);
I=[Top./Bottom]'
mesh(w,R,I)
When I run it I get this error:
Error using mesh (line 75)
Z must be a matrix, not a scalar or vector.
Error in ICA_4 (line 12)
mesh(w,R,I)

 採用された回答

Image Analyst
Image Analyst 2017 年 1 月 28 日
編集済み: Image Analyst 2017 年 1 月 28 日

0 投票

You were very close. You just had an error using mesh() instead of meshgrid as instructed. I corrected that plus a few other small things:
% Initialization / clean-up code.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Given Values
C = 15E-6;
Vm = 24;
L = 240E-3;
R = [10:1:40]
f = linspace(60,110,31);
[f2, R2] = meshgrid(f, R);
w = 2*pi*f;
w2 = 2*pi*f2;
% Compute function surface.
Top = Vm;
Bottom = sqrt(R2.^2 + (w2*L-(1./(w2.*C))).^2);
I = (Top./Bottom)';
% Now plot everything.
surf(R, w, I);
ylabel('omega (angular frequency)', 'FontSize', fontSize);
xlabel('R', 'FontSize', fontSize);
zlabel('I', 'FontSize', fontSize);
ydir ='reverse';
view(gca,[-133.1 34.8]);
grid(gca,'on');

2 件のコメント

Pape Traore
Pape Traore 2017 年 1 月 28 日
Thank you so much but does mesh grid exactly and what is ydir and gcc
Image Analyst
Image Analyst 2017 年 1 月 28 日
gca is the current axes. ydir just reverses the direction of the y axis. Actually I should have had this, to turn the omega axis around:
ax=gca;
ax.YDir ='reverse';

サインインしてコメントする。

その他の回答 (1 件)

Jan
Jan 2017 年 1 月 27 日

0 投票

Your w, R and I are vectors with 31 elements. The first input of mesh must be a matrix containing the Z values to the grid of x and y values.
The text of the assignment mentions, that meshgrid should be used.
Notes:
  • 15 *(10^-6) is an expensive power operation, while 15e-6 is a cheap constant. The runtime does not matter when you define one constant, but it is a good programming style to consider this.
  • 10:40 looks easier and is even faster than [10:1:40], see why-not-use-square-brackets.

1 件のコメント

Pape Traore
Pape Traore 2017 年 1 月 28 日
Thank you so much

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeParticle & Nuclear Physics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by